Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Compression And Encryption Re:

 [1/5] from: larry::ecotope::com at: 10-Sep-2000 17:41


Try http://www.rebol.com/library/html/encrypt.html You will also find some scripts that deal with using the built-in compress and decompress functions. HTH -Larry

 [2/5] from: trobrock:crosswinds at: 10-Sep-2000 19:05


Is there anyone or anywhere i can learn to make a rebol encryption script or a compression script?

 [3/5] from: al:bri:xtra at: 11-Sep-2000 11:30


> Is there anyone or anywhere i can learn to make a rebol encryption script
or a compression script? http://demo.rebol.net/cgi-bin/showfile.r?file=rip.r&keywords=[{.RIP}] That might help. Andrew Martin ICQ: 26227169 http://members.xoom.com/AndrewMartin/

 [4/5] from: civicminded4::yahoo at: 13-Sep-2000 12:29


--0-822890675-968873348=:20763 Content-Type: text/plain; charset=us-ascii Following inline is a candidate function/script for command line and within-script encryption of strings. Per the other comments in this thread, I provide this script as the basis for future work on such a function, and how it should work. The particular encryption scheme can later be changed (if necessary), once we work out _how_ we wan't the script to work. Until such a function is avaiable as a REBOL native or mezzanine, you have this function to play with. It uses the CipherSaber algorithm which is based on ARC4. rebol[ title: "String Encryption/Decryption Function (cipher)" version: 0.1.0 author: "alan parman email: [aparman--mail--com] comment: {This encryption is only as good as your passphrase. Your passphrase may be upto 246 characters. The longer the passphrase, stronger the encryption} ] cipher: func [{Candidate Function to encrypt/decrypt a string. Uses CipherSaber (copyright Arnold Reinhold), a version of ARC4} string [string!] "string to en-decrypt" /decrypt "decrypt the string" /pass "supply a passphrase without being prompted" supplied-pass [string!] "pre-supplied passphrase" /local passphrase initvector plaintextlength ][ ; this function both encrypts and decrypts, for the purposes of this function what goes in is plaintext what comes out is ciphertext ;regardless if you are encrypting or decrypting ;series swap, define a swapping function, needed for encryption engine******* s-swap: func ["swaps the elements of two series at the given index positions" a [series!] {1st series} index-a [integer!] {index position to swap in 1st series} b [series!] {2nd series} index-b [integer!] {index position to swap in 2nd series} /local holder ] [ holder: pick a index-a poke a index-a pick b index-b poke b index-b holder ] ;***** begin true works of function here either decrypt [ plaintext: decompress load string ] [ plaintext: string ] ;*****make or extract initvector, then set plaintext length initvector: make block! 10 either decrypt [ for n 1 10 1 [ append initvector to-char (pick plaintext n) ] remove/part plaintext 10 ] [ random/seed to-integer checksum/secure form now ; reduces chances of deciphering the date from initvector loop 10 [ append initvector to-char ((random 256) - 1) ;REBOL's random does 1 to N ] ] plaintextlength: length? plaintext ;*****get passphrase either pass [ passphrase: supplied-pass ][ passphrase: "" ] while [any [ (length? passphrase) > 246 passphrase = "" ] ][ if (length? passphrase) > 246 [print "Passphrase must be 246 characters or less"] passphrase: ask/hide "passphrase :>> " ] ;*****make key key: make block! [] foreach letter passphrase [ append key letter ] append key initvector keylength: length? key ;*****make state, a block from 0 to 255, in order state: make block! 256 for i 0 255 1 [append state i] ;*****mix state ;*******try a cs2 type addition, mixing 3 times for number 1 3 1 [ j: 0 ; remember do 0 to 255, not 1 to 256 ;i will index state i.e. each element is state(i) ;n is the index to cycle thru the key (i modulo keylength) ;j is the "randomly" choosen element of state for i 0 255 1 [; must add + 1 to index i as the arrays are accessed 1 2 3 ... 256 ;i.e. first element "0" is element 1 not element 0 n: i // keylength state-i: to-integer pick state (i + 1) key-n: to-integer pick key (n + 1) j: (j + state-i + key-n) // 256 s-swap state (i + 1) state (j + 1) ] ;end of for ] ;***** end of 'for' of cs2 addition ;***** produce the ciphertext i: j: n: 0 ciphertext: make block! [] ; contents of file going out if (not decrypt) [ append ciphertext initvector ] for count 0 (plaintextlength - 1) 1 [ i: ((count + 1) // 256) ; this "+1" is shown, but not clearly, on the instructions ; this is _not_ an indexing adjustment, it is an integral part of the ciphersaber process state-i: pick state (i + 1) j: ((j + state-i) // 256) s-swap state (i + 1) state (j + 1) n: (((pick state (i + 1)) + (pick state (j + 1))) // 256) append ciphertext (xor (to-char pick state (n + 1)) (to-char pick plaintext (count + 1))) ] ;end of for either decrypt [ ciphertext: to-string ciphertext ][ ciphertext: form compress to-string ciphertext ] unset [plaintext] return ciphertext ] ; end cipher [trobrock--crosswinds--net] wrote: Is there anyone or anywhere i can learn to make a rebol encryption script or a compression script? --0-822890675-968873348=:20763 Content-Type: text/html; charset=us-ascii <P>Following&nbsp;inline is a&nbsp;candidate&nbsp;function/script for command line and within-script encryption of strings.</P> <P>Per the other comments in this thread, I provide this script as the basis for future work on such a function, and how it should work.&nbsp; The particular encryption scheme can later be changed (if necessary), once we work out _how_ we wan't the script to work.</P> <P>Until such a function is avaiable as a REBOL native or mezzanine, you have this function to play with.</P> <P>It uses the CipherSaber algorithm which is based on ARC4.</P> <P>rebol[<BR>title: "String Encryption/Decryption Function (cipher)"<BR>version: 0.1.0<BR>author: "alan parman<BR>email: <A href="mailto:[aparman--mail--com]">[aparman--mail--com]</A><BR>comment: {This encryption is only as good as your passphrase.&nbsp; Your passphrase may be upto 246 characters. The longer the passphrase, stronger the encryption}<BR>]</P> <P>cipher: func [{Candidate Function to encrypt/decrypt a string.<BR>&nbsp;Uses CipherSaber (copyright Arnold Reinhold), a version of ARC4}<BR>string [string!] "string to en-decrypt"<BR>/decrypt "decrypt the string"<BR>/pass "supply a passphrase without being prompted" <BR>supplied-pass [string!]&nbsp; "pre-supplied passphrase"<BR>/local passphrase initvector plaintextlength<BR>][<BR>; this function both encrypts and decrypts, for the purposes of this function what goes in is plaintext what comes out is ciphertext<BR>;regardless if you are encrypting or decrypting</P> <P>;series swap, define a swapping function, needed for encryption engine*******<BR>s-swap: func ["swaps the elements of two series at the given index positions"<BR>&nbsp;a [series!] {1st series}<BR>&nbsp;index-a [integer!] {index position to swap in 1st series}<BR>&nbsp;b [series!] {2nd series}<BR>&nbsp;index-b [integer!] {index position to swap in 2nd series}<BR>&nbsp;/local holder<BR>] [<BR>&nbsp;holder: pick a index-a<BR>&nbsp;poke a index-a pick b index-b<BR>&nbsp;poke b index-b holder<BR>]</P> <P>;***** begin true works of function here</P> <P>either decrypt [<BR>&nbsp;plaintext: decompress load string<BR>] [<BR>&nbsp;plaintext: string<BR>]</P> <P>&nbsp;;*****make or extract initvector,&nbsp; then set plaintext length<BR>&nbsp;initvector: make block! 10<BR>&nbsp;either decrypt&nbsp; [<BR>&nbsp;&nbsp;for n 1 10 1 [<BR>&nbsp;&nbsp;&nbsp;append initvector to-char (pick plaintext n)<BR>&nbsp;&nbsp;]<BR>&nbsp;&nbsp;remove/part plaintext 10<BR>&nbsp;] [<BR>&nbsp;&nbsp;random/seed to-integer checksum/secure form now ; reduces chances of deciphering the date from initvector<BR>&nbsp;&nbsp;loop 10 [<BR>&nbsp;&nbsp;&nbsp;append initvector to-char ((random 256) - 1) ;REBOL's random does 1 to N<BR>&nbsp;&nbsp;]<BR>&nbsp;]</P> <P>&nbsp;plaintextlength: length? plaintext</P> <P>&nbsp;;*****get passphrase<BR>&nbsp;either pass [<BR>&nbsp;&nbsp;passphrase: supplied-pass<BR>&nbsp;][<BR>&nbsp;&nbsp;passphrase: ""<BR>&nbsp;]</P> <P>&nbsp;while [any [<BR>&nbsp;&nbsp;(length? passphrase) > 246<BR>&nbsp;&nbsp;passphrase = ""<BR>&nbsp;&nbsp;]<BR>&nbsp;][<BR>&nbsp;&nbsp;if (length? passphrase) > 246 [print "Passphrase must be 246 characters or less"]<BR>&nbsp;&nbsp;passphrase: ask/hide "passphrase :>> "<BR>&nbsp;]</P> <P>&nbsp;;*****make key<BR>&nbsp;key: make block! []<BR>&nbsp;foreach letter passphrase [<BR>&nbsp;&nbsp;append key letter<BR>&nbsp;]<BR>&nbsp;append key initvector<BR>&nbsp;keylength: length? key</P> <P>&nbsp;;*****make state, a block from 0 to 255, in order<BR>&nbsp;state: make block! 256<BR>&nbsp;for i 0 255 1 [append state i]</P> <P>&nbsp;;*****mix state<BR>&nbsp;;*******try a cs2 type addition, mixing 3 times<BR>&nbsp;for number 1 3 1 [<BR>&nbsp;&nbsp;j: 0 ; remember do 0 to 255, not 1 to 256<BR>&nbsp;&nbsp;;i will index state i.e. each element is state(i)<BR>&nbsp;&nbsp;;n is the index to cycle thru the key (i modulo keylength)<BR>&nbsp;&nbsp;;j is the "randomly" choosen element of state</P> <P>&nbsp;&nbsp;for i 0 255 1 [; must add + 1 to index i as the arrays are accessed 1 2 3 ... 256 <BR>&nbsp;&nbsp;&nbsp;;i.e. first element "0" is element 1 not element 0<BR>&nbsp;&nbsp;&nbsp;n: i // keylength</P> <P>&nbsp;&nbsp;&nbsp;state-i: to-integer pick state (i + 1)<BR>&nbsp;&nbsp;&nbsp;key-n: to-integer pick key (n + 1)</P> <P>&nbsp;&nbsp;&nbsp;j: (j + state-i + key-n) // 256</P> <P>&nbsp;&nbsp;&nbsp;s-swap state (i + 1) state (j + 1)</P> <P>&nbsp;&nbsp;] ;end of for<BR>&nbsp;] ;***** end of 'for' of cs2 addition</P> <P>&nbsp;;***** produce the ciphertext<BR>&nbsp;i: j: n: 0</P> <P>&nbsp;ciphertext: make block! [] ; contents of file going out</P> <P>&nbsp;if (not decrypt) [<BR>&nbsp;&nbsp;append ciphertext initvector<BR>&nbsp;]</P> <P>&nbsp;for count 0 (plaintextlength - 1) 1 [<BR>&nbsp;&nbsp;i: ((count + 1) // 256) ; this "+1" is shown, but not clearly, on the instructions<BR>&nbsp;&nbsp;; this is _not_ an indexing adjustment, it is an integral part of the ciphersaber process</P> <P>&nbsp;&nbsp;state-i: pick state (i + 1)</P> <P>&nbsp;&nbsp;j: ((j + state-i) // 256)</P> <P>&nbsp;&nbsp;s-swap state (i + 1) state (j + 1)</P> <P>&nbsp;&nbsp;n: (((pick state (i + 1)) + (pick state (j + 1))) // 256)</P> <P>&nbsp;&nbsp;append ciphertext&nbsp; (xor (to-char pick state (n + 1)) (to-char pick plaintext (count + 1)))</P> <P>&nbsp;] ;end of for </P> <P><BR>&nbsp;either decrypt [<BR>&nbsp;&nbsp;ciphertext:&nbsp; to-string ciphertext&nbsp;&nbsp;<BR>&nbsp;][<BR>&nbsp;&nbsp;ciphertext: form compress to-string ciphertext<BR>&nbsp;]<BR>unset [plaintext]<BR>return ciphertext</P> <P>] ; end cipher</P> <P><BR>&nbsp;</P> <P>&nbsp; <B><I>[trobrock--crosswinds--net]</I></B> wrote: <BR> <BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid"> <P>Is there anyone or anywhere i can learn to make a rebol encryption script or<BR>a compression script?</P></BLOCKQUOTE> --0-822890675-968873348=:20763--

 [5/5] from: civicminded4::yahoo at: 13-Sep-2000 12:50


--0-1681692777-968874604=:23812 Content-Type: text/plain; charset=us-ascii Sorry there was a minor typo in the last script, use this one instead! rebol[ title: "String Encryption/Decryption Function (cipher)" version: 0.1.0 author: "alan parman" email: [aparman--mail--com] comment: {This encryption is only as good as your passphrase. Your passphrase may be upto 246 characters. The longer the passphrase, stronger the encryption} ] cipher: func [{Candidate Function to encrypt/decrypt a string. Uses CipherSaber (copyright Arnold Reinhold), a version of ARC4} string [string!] "string to en-decrypt" /decrypt "decrypt the string" /pass "supply a passphrase without being prompted" supplied-pass [string!] "pre-supplied passphrase" /local passphrase initvector plaintextlength ][ ; this function both encrypts and decrypts, for the purposes of this function what goes in is plaintext what comes out is ciphertext ;regardless if you are encrypting or decrypting ;series swap, define a swapping function, needed for encryption engine******* s-swap: func ["swaps the elements of two series at the given index positions" a [series!] {1st series} index-a [integer!] {index position to swap in 1st series} b [series!] {2nd series} index-b [integer!] {index position to swap in 2nd series} /local holder ] [ holder: pick a index-a poke a index-a pick b index-b poke b index-b holder ] ;***** begin true works of function here either decrypt [ plaintext: decompress load string ] [ plaintext: string ] ;*****make or extract initvector, then set plaintext length initvector: make block! 10 either decrypt [ for n 1 10 1 [ append initvector to-char (pick plaintext n) ] remove/part plaintext 10 ] [ random/seed to-integer checksum/secure form now ; reduces chances of deciphering the date from initvector loop 10 [ append initvector to-char ((random 256) - 1) ;REBOL's random does 1 to N ] ] plaintextlength: length? plaintext ;*****get passphrase either pass [ passphrase: supplied-pass ][ passphrase: "" ] while [any [ (length? passphrase) > 246 passphrase = "" ] ][ if (length? passphrase) > 246 [print "Passphrase must be 246 characters or less"] passphrase: ask/hide "passphrase :>> " ] ;*****make key key: make block! [] foreach letter passphrase [ append key letter ] append key initvector keylength: length? key ;*****make state, a block from 0 to 255, in order state: make block! 256 for i 0 255 1 [append state i] ;*****mix state ;*******try a cs2 type addition, mixing 3 times for number 1 3 1 [ j: 0 ; remember do 0 to 255, not 1 to 256 ;i will index state i.e. each element is state(i) ;n is the index to cycle thru the key (i modulo keylength) ;j is the "randomly" choosen element of state for i 0 255 1 [; must add + 1 to index i as the arrays are accessed 1 2 3 ... 256 ;i.e. first element "0" is element 1 not element 0 n: i // keylength state-i: to-integer pick state (i + 1) key-n: to-integer pick key (n + 1) j: (j + state-i + key-n) // 256 s-swap state (i + 1) state (j + 1) ] ;end of for ] ;***** end of 'for' of cs2 addition ;***** produce the ciphertext i: j: n: 0 ciphertext: make block! [] ; contents of file going out if (not decrypt) [ append ciphertext initvector ] for count 0 (plaintextlength - 1) 1 [ i: ((count + 1) // 256) ; this "+1" is shown, but not clearly, on the instructions ; this is _not_ an indexing adjustment, it is an integral part of the ciphersaber process state-i: pick state (i + 1) j: ((j + state-i) // 256) s-swap state (i + 1) state (j + 1) n: (((pick state (i + 1)) + (pick state (j + 1))) // 256) append ciphertext (xor (to-char pick state (n + 1)) (to-char pick plaintext (count + 1))) ] ;end of for either decrypt [ ciphertext: to-string ciphertext ][ ciphertext: form compress to-string ciphertext ] unset [plaintext] return ciphertext ] ; end cipher --0-1681692777-968874604=:23812 Content-Type: text/html; charset=us-ascii <P> <BR>Sorry there was a minor typo in the last script, use this one instead! <P>&nbsp; <P>rebol[<BR>title: "String Encryption/Decryption Function (cipher)"<BR>version: 0.1.0<BR>author: "alan parman"<BR>email: <A href="mailto:[aparman--mail--com]">[aparman--mail--com]</A><BR>comment: {This encryption is only as good as your passphrase.&nbsp; Your passphrase may be upto 246 characters. The longer the passphrase, stronger the encryption}<BR>] <P>cipher: func [{Candidate Function to encrypt/decrypt a string.<BR>&nbsp;Uses CipherSaber (copyright Arnold Reinhold), a version of ARC4}<BR>string [string!] "string to en-decrypt"<BR>/decrypt "decrypt the string"<BR>/pass "supply a passphrase without being prompted" <BR>supplied-pass [string!]&nbsp; "pre-supplied passphrase"<BR>/local passphrase initvector plaintextlength<BR>][<BR>; this function both encrypts and decrypts, for the purposes of this function what goes in is plaintext what comes out is ciphertext<BR>;regardless if you are encrypting or decrypting <P>;series swap, define a swapping function, needed for encryption engine*******<BR>s-swap: func ["swaps the elements of two series at the given index positions"<BR>&nbsp;a [series!] {1st series}<BR>&nbsp;index-a [integer!] {index position to swap in 1st series}<BR>&nbsp;b [series!] {2nd series}<BR>&nbsp;index-b [integer!] {index position to swap in 2nd series}<BR>&nbsp;/local holder<BR>] [<BR>&nbsp;holder: pick a index-a<BR>&nbsp;poke a index-a pick b index-b<BR>&nbsp;poke b index-b holder<BR>] <P>;***** begin true works of function here <P>either decrypt [<BR>&nbsp;plaintext: decompress load string<BR>] [<BR>&nbsp;plaintext: string<BR>] <P>&nbsp;;*****make or extract initvector,&nbsp; then set plaintext length<BR>&nbsp;initvector: make block! 10<BR>&nbsp;either decrypt&nbsp; [<BR>&nbsp;&nbsp;for n 1 10 1 [<BR>&nbsp;&nbsp;&nbsp;append initvector to-char (pick plaintext n)<BR>&nbsp;&nbsp;]<BR>&nbsp;&nbsp;remove/part plaintext 10<BR>&nbsp;] [<BR>&nbsp;&nbsp;random/seed to-integer checksum/secure form now ; reduces chances of deciphering the date from initvector<BR>&nbsp;&nbsp;loop 10 [<BR>&nbsp;&nbsp;&nbsp;append initvector to-char ((random 256) - 1) ;REBOL's random does 1 to N<BR>&nbsp;&nbsp;]<BR>&nbsp;] <P>&nbsp;plaintextlength: length? plaintext <P>&nbsp;;*****get passphrase<BR>&nbsp;either pass [<BR>&nbsp;&nbsp;passphrase: supplied-pass<BR>&nbsp;][<BR>&nbsp;&nbsp;passphrase: ""<BR>&nbsp;] <P>&nbsp;while [any [<BR>&nbsp;&nbsp;(length? passphrase) > 246<BR>&nbsp;&nbsp;passphrase = ""<BR>&nbsp;&nbsp;]<BR>&nbsp;][<BR>&nbsp;&nbsp;if (length? passphrase) > 246 [print "Passphrase must be 246 characters or less"]<BR>&nbsp;&nbsp;passphrase: ask/hide "passphrase :>> "<BR>&nbsp;] <P>&nbsp;;*****make key<BR>&nbsp;key: make block! []<BR>&nbsp;foreach letter passphrase [<BR>&nbsp;&nbsp;append key letter<BR>&nbsp;]<BR>&nbsp;append key initvector<BR>&nbsp;keylength: length? key <P>&nbsp;;*****make state, a block from 0 to 255, in order<BR>&nbsp;state: make block! 256<BR>&nbsp;for i 0 255 1 [append state i] <P>&nbsp;;*****mix state<BR>&nbsp;;*******try a cs2 type addition, mixing 3 times<BR>&nbsp;for number 1 3 1 [<BR>&nbsp;&nbsp;j: 0 ; remember do 0 to 255, not 1 to 256<BR>&nbsp;&nbsp;;i will index state i.e. each element is state(i)<BR>&nbsp;&nbsp;;n is the index to cycle thru the key (i modulo keylength)<BR>&nbsp;&nbsp;;j is the "randomly" choosen element of state <P>&nbsp;&nbsp;for i 0 255 1 [; must add + 1 to index i as the arrays are accessed 1 2 3 ... 256 <BR>&nbsp;&nbsp;&nbsp;;i.e. first element "0" is element 1 not element 0<BR>&nbsp;&nbsp;&nbsp;n: i // keylength <P>&nbsp;&nbsp;&nbsp;state-i: to-integer pick state (i + 1)<BR>&nbsp;&nbsp;&nbsp;key-n: to-integer pick key (n + 1) <P>&nbsp;&nbsp;&nbsp;j: (j + state-i + key-n) // 256 <P>&nbsp;&nbsp;&nbsp;s-swap state (i + 1) state (j + 1) <P>&nbsp;&nbsp;] ;end of for<BR>&nbsp;] ;***** end of 'for' of cs2 addition <P>&nbsp;;***** produce the ciphertext<BR>&nbsp;i: j: n: 0 <P>&nbsp;ciphertext: make block! [] ; contents of file going out <P>&nbsp;if (not decrypt) [<BR>&nbsp;&nbsp;append ciphertext initvector<BR>&nbsp;] <P>&nbsp;for count 0 (plaintextlength - 1) 1 [<BR>&nbsp;&nbsp;i: ((count + 1) // 256) ; this "+1" is shown, but not clearly, on the instructions<BR>&nbsp;&nbsp;; this is _not_ an indexing adjustment, it is an integral part of the ciphersaber process <P>&nbsp;&nbsp;state-i: pick state (i + 1) <P>&nbsp;&nbsp;j: ((j + state-i) // 256) <P>&nbsp;&nbsp;s-swap state (i + 1) state (j + 1) <P>&nbsp;&nbsp;n: (((pick state (i + 1)) + (pick state (j + 1))) // 256) <P>&nbsp;&nbsp;append ciphertext&nbsp; (xor (to-char pick state (n + 1)) (to-char pick plaintext (count + 1))) <P>&nbsp;] ;end of for <P><BR>&nbsp;either decrypt [<BR>&nbsp;&nbsp;ciphertext:&nbsp; to-string ciphertext&nbsp;&nbsp;<BR>&nbsp;][<BR>&nbsp;&nbsp;ciphertext: form compress to-string ciphertext<BR>&nbsp;]<BR>unset [plaintext]<BR>return ciphertext <P>] ; end cipher</P> --0-1681692777-968874604=:23812--