Skip to content

Instantly share code, notes, and snippets.

@dockimbel
Last active August 15, 2019 21:47
Show Gist options
  • Save dockimbel/f6c90a135b7ef96c8ef693ce014cbc99 to your computer and use it in GitHub Desktop.
Save dockimbel/f6c90a135b7ef96c8ef693ce014cbc99 to your computer and use it in GitHub Desktop.
Red generator for encoded messaged
Red [
Purpose: {
Red generator for encoded messaged as in:
http://www.rebol.com/oneliners.html#section-17
}
]
gen-hack: function [secret [string!]][
;-- First build a list of integers from 1 to the last index of the secret string
table: collect [repeat i len: length? secret [keep i]]
;-- Pick a seed from the secret itself
random/seed s: pick secret random len
;-- Shuffle the integers list with that seed. This results in a table of decoding indexes.
table: random table
;-- Encrypt the message by selecting each character using that table
collect/into [repeat i len [keep pick secret index? find table i]] masked: copy ""
;-- Find the index of the selected seed character in the encrypted message
i: index? find masked s
;-- Generate the line of code with the encrypted secret
print mold/only compose [random/seed pick sig: copy (masked) (i) random sig]
]
gen-hack "Just another Red hacker!"
; == random/seed pick sig: copy "kecneodersu htRaJ rah!t" 12 random sig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment