Skip to content

Instantly share code, notes, and snippets.

@eflukx
Created April 7, 2023 10:14
Show Gist options
  • Save eflukx/da2a9e991a9a08225ce510309e3fba04 to your computer and use it in GitHub Desktop.
Save eflukx/da2a9e991a9a08225ce510309e3fba04 to your computer and use it in GitHub Desktop.
# Array get cycle
# KEY cyclical enumerator
KEY = "code"
SYMBOLS = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z","1","2","3"]
def encrypt(input_text)
crypt input_text, false
end
def decrypt(input_text)
crypt input_text, true
end
def crypt(input_text, decrypt)
key_idx = -1
input_text.chars.map do |letter|
if letter == " "
letter
else
key_idx += 1
draaing = decrypt ? -key_index(key_idx) : key_index(key_idx)
letter_mepper letter, draaing
end
end.join
end
def key_index offset
SYMBOLS.find_index(key_letter(offset))
end
def key_letter offset
KEY[offset % KEY.length]
end
def letter_mepper(input_symbol, draaing)
new_index = SYMBOLS.find_index(input_symbol) + draaing
SYMBOLS[new_index % SYMBOLS.length]
end
input = "jij hebt dit voor helemaal niks ontcijferd"
ciphertext = encrypt(input)
puts "'#{input}' encrypted is '#{ciphertext}'"
decrypted = decrypt(ciphertext)
puts "'#{ciphertext}' decrypted is '#{decrypted}'"
@eflukx
Copy link
Author

eflukx commented Apr 7, 2023

De Caesar en-/decryptor van Brecht uit de Feynmanklas!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment