Created
November 19, 2019 20:39
-
-
Save kitofr/95f2eb13e3449bdfc22e3df91f0a8edf to your computer and use it in GitHub Desktop.
A ruby implementation of the scout chipher
This file contains hidden or 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
# | S | C | O | U | T | | |
# s | A | B | C | D | E | | |
# c | F | G | H | I | J | | |
# o | K | L | M | N | O | | |
# u | P | R | S | T | U | | |
# t | V | Y | Å | Ä | Ö | | |
def alphabet | |
{ | |
'A': 'Ss', 'B': 'Cs', 'C': 'Os', 'D': 'Us', 'E': 'Ts', | |
'F': 'Sc', 'G': 'Cc', 'H': 'Oc', 'I': 'Uc', 'J': 'Tc', | |
'K': 'So', 'L': 'Co', 'M': 'Oo', 'N': 'Uo', 'O': 'To', | |
'P': 'Su', 'R': 'Cu', 'S': 'Ou', 'T': 'Uu', 'U': 'Tu', | |
'V': 'St', 'Y': 'Ct', 'Å': 'Ot', 'Ä': 'Ut', 'Ö': 'Tt', | |
' ': ' ', '!': '!', | |
} | |
end | |
def reverse | |
{ | |
'Ss': 'A', 'Cs': 'B', 'Os': 'C', 'Us': 'D', 'Ts': 'E', | |
'Sc': 'F', 'Cc': 'G', 'Oc': 'H', 'Uc': 'I', 'Tc': 'J', | |
'So': 'K', 'Co': 'L', 'Oo': 'M', 'Uo': 'N', 'To': 'O', | |
'Su': 'P', 'Cu': 'R', 'Ou': 'S', 'Uu': 'T', 'Tu': 'U', | |
'St': 'V', 'Ct': 'Y', 'Ot': 'Å', 'Ut': 'Ä', 'Tt': 'Ö', | |
' ': ' ', '!!': '!', | |
} | |
end | |
def cipher words | |
words.each_char.map{ |ch| alphabet[ch.to_sym] }.join | |
end | |
def decipher crypto | |
crypto | |
.gsub(/ /, " ") | |
.gsub(/!/, "!!") | |
.each_char | |
.each_slice(2) | |
.map {|t| reverse[t.join.to_sym] } | |
.join | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Then you can do something like