Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #58912
| From | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Rosetta: Caesar cipher |
| Date | 2017-05-09 20:47 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <oet9tb$166r$1@gioia.aioe.org> (permalink) |
> Implement a Caesar cipher, both encoding and decoding.
> The key is an integer from 1 to 25.
>
> This cipher rotates (either towards left or right) the letters
> of the alphabet (A to Z).
>
> The encoding replaces each letter with the 1st to 25th next
> letter in the alphabet (wrapping Z to A).
>
> So key 2 encrypts "HI" to "JK", but key 20 encrypts "HI" to "BC".
(use srfi-13)
(define lower-alphabet
(string-tabulate
(lambda(i) (integer->char (+ (char->integer #\a) i))) 26))
(define (shifted-alphabet n)
;; Rotate the lowercase letters.
(define s (xsubstring lower-alphabet n))
(string-append s (string-upcase s)))
(define (encipher n str)
(string-translate str
(shifted-alphabet 0)
(shifted-alphabet n)))
(define (decipher n str) (encipher (- n) str))
(encipher 3 "However, the man wasn't there.[9]")
===>
"Krzhyhu, wkh pdq zdvq'w wkhuh.[9]"
(decipher 3 (encipher 3 "However, the man wasn't there.[9]"))
===>
"However, the man wasn't there.[9]"
In Forth?
--
[W]e had enough employees who made more than 85 to fill all the openings. The
highest score that any of the blacks scored on the test was 11. The lowest
score that any black made on the test was 4. All four of those blacks went
into skilled-trades training.
https://archive.org/download/TheOldmanArchives/oldman29-081003.mp3
Back to comp.lang.forth | Previous | Next — Next in thread | Find similar | Unroll thread
Rosetta: Caesar cipher "Robert L." <No_spamming@noWhere_7073.org> - 2017-05-09 20:47 +0000
Re: Rosetta: Caesar cipher Joel Rees <joel.rees@gmail.com> - 2017-05-09 20:20 -0700
Re: Rosetta: Caesar cipher hughaguilar96@gmail.com - 2017-05-12 13:52 -0700
Re: Rosetta: Caesar cipher rickman <gnuarm@gmail.com> - 2017-05-10 20:07 -0400
Re: Rosetta: Caesar cipher Julian Fondren <julian.fondren@gmail.com> - 2017-05-10 21:12 -0700
Re: Rosetta: Caesar cipher rickman <gnuarm@gmail.com> - 2017-05-11 01:50 -0400
Re: Rosetta: Caesar cipher Julian Fondren <julian.fondren@gmail.com> - 2017-05-11 05:34 -0700
Re: Rosetta: Caesar cipher Alex <alex@rivadpm.com> - 2017-05-11 14:39 +0100
Re: Rosetta: Caesar cipher anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-05-11 16:04 +0000
Re: Rosetta: Caesar cipher Alex <alex@rivadpm.com> - 2017-05-11 21:35 +0100
Re: Rosetta: Caesar cipher mhx@iae.nl - 2017-05-11 10:21 -0700
Re: Rosetta: Caesar cipher rickman <gnuarm@gmail.com> - 2017-05-12 13:41 -0400
csiph-web