rc4(n)
π 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
-inchannel
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
rc4command, or - a filename, or
- a pre-opened channel
let's break it down bestie:
- if the
-infileargument is given, then the file is opened, the data is read and processed, and the file is closed. bye girl π - if the
-inargument is given, then data is read from the channel until the end of file. the channel is not closed. she stays open. - if the
-outargument 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,-inor 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 callingRC4Init.::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 β
the whole cipher friend group π
π KEYWORDS π
arcfour, data integrity, encryption, rc4, security, stream cipher
π CATEGORY π
Hashes, checksums, and encryption
πΈ COPYRIGHT πΈ
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
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- Copyright (c) 2003, Pat Thoyts <patthoyts@users\&.sourceforge\&.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms