Last active
August 15, 2019 21:47
-
-
Save dockimbel/f6c90a135b7ef96c8ef693ce014cbc99 to your computer and use it in GitHub Desktop.
Red generator for encoded messaged
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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