fork download
  1. ; two-way cipher
  2.  
  3. (define (plus str1 str2)
  4. (list->string
  5. (map (lambda (x y)
  6. (integer->char
  7. (+ (modulo
  8. (+ (- (char->integer x) 65)
  9. (- (char->integer y) 65))
  10. 26)
  11. 65)))
  12. (string->list str1) (string->list str2))))
  13.  
  14. (define (minus str1 str2)
  15. (list->string
  16. (map (lambda (x y)
  17. (integer->char
  18. (+ (modulo
  19. (- (- (char->integer x) 65)
  20. (- (char->integer y) 65))
  21. 26)
  22. 65)))
  23. (string->list str1) (string->list str2))))
  24.  
  25. (define plaintext1 "PROGRAMMING")
  26. (define plaintext2 "PRAXISXXXXX")
  27.  
  28. (define ciphertext "ABCDEFGHIJK")
  29.  
  30. (define key1 (minus ciphertext plaintext1))
  31. (define key2 (minus ciphertext plaintext2))
  32.  
  33. (display key1) (newline)
  34. (display key2) (newline)
  35.  
  36. (display (minus ciphertext key1)) (newline)
  37. (display (minus ciphertext key2)) (newline)
Success #stdin #stdout 0.01s 8672KB
stdin
Standard input is empty
stdout
LKOXNFUVAWE
LKCGWNJKLMN
PROGRAMMING
PRAXISXXXXX