Skip to content

Instantly share code, notes, and snippets.

@kitofr
Created November 19, 2019 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kitofr/95f2eb13e3449bdfc22e3df91f0a8edf to your computer and use it in GitHub Desktop.
Save kitofr/95f2eb13e3449bdfc22e3df91f0a8edf to your computer and use it in GitHub Desktop.
A ruby implementation of the scout chipher
# | 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
@kitofr
Copy link
Author

kitofr commented Nov 19, 2019

Then you can do something like

pry(main)> load './chipher.rb'
=> true
pry(main)> cipher "MÅNEN ÄR BÄST!"
=> "OoOtUoTsUo UtCu CsUtOuUu!"
pry(main)> decipher cipher "MÅNEN ÄR BÄST!"
=> "MÅNEN ÄR BÄST!"
pry(main)>

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