vigenere_cipher.sf 434 B

123456789101112131415
  1. #!/usr/bin/ruby
  2. func s2v(s) { s.uc.scan(/[A-Z]/)»ord»() »-» 65 };
  3. func v2s(v) { (v »%» 26 »+» 65)»chr»() -> join };
  4. func blacken (red, key) { v2s(s2v(red) »+« s2v(key)) };
  5. func redden (blk, key) { v2s(s2v(blk) »-« s2v(key)) };
  6. var red = "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!";
  7. var key = "Vigenere Cipher!!!";
  8. say red;
  9. say (var black = blacken(red, key));
  10. say redden(black, key);