rc4(n)

πŸ“¦
version 2.0 Β· 2 versions
, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

πŸ’… rc4(n) β€” RC4 Stream Cipher, bestie edition

ok so like. this is the manual page for rc4, and it's giving cryptography main character energy. it lives in tcllib, it's a Tcl implementation of a stream cipher, and honestly? iconic. let's get into it πŸŽ€


✨ NAME ✨

rc4 β€” Implementation of the RC4 stream cipher


🌸 SYNOPSIS 🌸

package require Tcl 8.5 9

package require rc4 ?1.2.0?

::rc4::rc4  ?-hex?  -key  keyvalue  ?-command  lst? ?-out channel? [ -in
channel | -infile filename | string ]

::rc4::RC4Init keydata

::rc4::RC4 Key data

::rc4::RC4Final Key

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so boom: this package is an implementation in Tcl of the RC4 stream cipher, and it was developed by Ron Rivest over at RSA Data Security Inc. πŸ’–

the cipher was literally a trade secret of RSA, but then it got reverse-engineered and published to the internet in 1994. not the girls leaking the secrets 😭 anyway. it's used in a bunch of network protocols for securing communications.

and listen β€” to evade trademark restrictions, this cipher is sometimes known as ARCFOUR. same vibe, different name, iykyk. πŸ’…


πŸ‘‘ COMMANDS πŸ‘‘

::rc4::rc4 ?-hex? -key keyvalue ?-command lst? ?-out channel? [ -in channel | -infile filename | string ]

this is the one. it performs the RC4 algorithm on either:

  • the data provided by the argument, or
  • the data read from the -in channel

if an -out channel is given, then the result gets written to that channel. giving the -hex option will return a hexadecimal encoded version of the result if you're not using an -out channel. no cap.

the data to be processed can be specified either as:

  • a string argument to the rc4 command, or
  • a filename, or
  • a pre-opened channel

let's break it down bestie:

  • if the -infile argument is given, then the file is opened, the data is read and processed, and the file is closed. bye girl πŸ‘‹
  • if the -in argument is given, then data is read from the channel until the end of file. the channel is not closed. she stays open.
  • if the -out argument is given, then the processing result is written to this channel.

now, if -command is provided, then the rc4 command does not return anything. instead, the command you provided gets called with the rc4 result data appended as the final parameter. this is most useful when reading from Tcl channels, because a fileevent is set up on the channel and the data gets processed in chunks ✨

⚠️ only one of -infile, -in or string should be given. pick a lane bestie, one lane. πŸ™ˆ

🧚 PROGRAMMING INTERFACE 🧚

  • ::rc4::RC4Init keydata β€” initialize a new RC4 key. the keydata is any amount of binary data and is used to initialize the cipher internal state. slay πŸ’–
  • ::rc4::RC4 Key data β€” encrypt or decrypt the input data using the Key obtained by calling RC4Init.
  • ::rc4::RC4Final Key β€” this should be called to clean up resources associated with Key. once this function has been called the key is destroyed. gone. periodt. πŸ’€

🌈 EXAMPLES 🌈

% set keydata [binary format H* 0123456789abcdef]
% rc4::rc4 -hex -key $keydata HelloWorld
3cf1ae8b7f1c670b612f
% rc4::rc4 -key $keydata [binary format H* 3cf1ae8b7f1c670b612f]
HelloWorld

 set Key [rc4::RC4Init "key data"]
 append ciphertext [rc4::RC4 $Key $plaintext]
 append ciphertext [rc4::RC4 $Key $additional_plaintext]
 rc4::RC4Final $Key

 proc ::Finish {myState data} {
     DoStuffWith $myState $data
 }
 rc4::rc4 -in $socket -command [list ::Finish $ApplicationState]

look at her go. encrypt, decrypt, back to HelloWorld. the range? unmatched. πŸ”₯


πŸ’œ AUTHORS πŸ’œ

Pat Thoyts


πŸ™ˆ BUGS, IDEAS, FEEDBACK πŸ™ˆ

this document, and the package it describes, will undoubtedly contain bugs and other problems. ngl, they said it themselves. please report such in the category rc4 of the Tcllib Trackers at [http://core.tcl.tk/tcllib/reportlist]. also please report any ideas for enhancements you may have for either the package and/or the documentation. we love a glow-up suggestion 🫢

when proposing code changes, please provide unified diffs, i.e the output of diff -u.

note further that attachments are strongly preferred over inlined patches. attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. (yes that specific button, the left-most one, she's the moment πŸ‘‘)


⭐ SEE ALSO ⭐

aes(n), blowfish(n), des(n)

the whole cipher friend group πŸ’–


πŸ“ KEYWORDS πŸ“

arcfour, data integrity, encryption, rc4, security, stream cipher


πŸŽ€ CATEGORY πŸŽ€

Hashes, checksums, and encryption


Copyright (c) 2003, Pat Thoyts <patthoyts@users.sourceforge.net>


ok that's the whole page bestie, you ate πŸ’…βœ¨ this was tcllib version 1.2.0 talking about rc4(n) β€” go forth, encrypt responsibly, and remember: only one of -infile, -in or string. mwah πŸ«ΆπŸ’–

πŸ“¦ where this page comes from