Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
41
Task/Substitution-cipher/Emacs-Lisp/substitution-cipher.l
Normal file
41
Task/Substitution-cipher/Emacs-Lisp/substitution-cipher.l
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
(setq alphabet "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
(setq code "odrmqbjnwzvueghlacyfpktisxODRMQBJNWZVUEGHLACYFPKTISX")
|
||||
|
||||
(defun encode (text)
|
||||
"Encode TEXT with simple substitution code.
|
||||
Each letter is replaced with the a random letter.
|
||||
A specific letter in the original will always be replaced
|
||||
by the same coded letter."
|
||||
(let* ((case-fold-search nil)
|
||||
(text-length (length text))
|
||||
(encoded-text "")
|
||||
(current-letter "")
|
||||
(coded-letter "")
|
||||
(alphabet-position))
|
||||
(dotimes (i text-length)
|
||||
(setq current-letter (substring text i (+ 1 i))) ; find the next letter in TEXT
|
||||
(if (not (string-match-p "[a-zA-Z]" current-letter)) ; IF it's not a letter
|
||||
(setq coded-letter current-letter) ; pass the non-letter without change
|
||||
(setq alphabet-position (string-match current-letter alphabet)) ; ELSE find where the letter is in ALPHABET
|
||||
(setq coded-letter (substring code alphabet-position (+ 1 alphabet-position)))) ; AND pass the coded letter
|
||||
(setq encoded-text (concat encoded-text coded-letter))) ; IN ANY CASE, add new letter to ENCODED-TEXT
|
||||
encoded-text))
|
||||
|
||||
(defun decode (text)
|
||||
"Decode TEXT encoded with simple substitution code.
|
||||
Each coded letter is replaced with the corresponding
|
||||
uncoded letter."
|
||||
(let* ((case-fold-search nil)
|
||||
(text-length (length text))
|
||||
(uncoded-text "")
|
||||
(current-letter "")
|
||||
(uncoded-letter "")
|
||||
(code-position))
|
||||
(dotimes (i text-length)
|
||||
(setq current-letter (substring text i (+ 1 i))) ; find the next letter in TEXT
|
||||
(if (not (string-match-p "[a-zA-Z]" current-letter)) ; IF it's not a letter
|
||||
(setq uncoded-letter current-letter) ; pass the non-letter without change
|
||||
(setq code-position (string-match current-letter code)) ; ELSE find where the letter is in CODE
|
||||
(setq uncoded-letter (substring alphabet code-position (+ 1 code-position)))) ; AND pass the uncoded letter
|
||||
(setq uncoded-text (concat uncoded-text uncoded-letter))) ; IN ANY CASE, add new letter to UNCODED-TEXT
|
||||
uncoded-text))
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
{$zerobasedstrings}
|
||||
|
||||
var key := ']kYV}(!7P$n5_0i R:?jOWtF/=-pe''AD&@r6%ZXs"v*N[#wSl9zq2^+g;LoB`aGh{3.HIu4fbK)mU8|dMET><,Qc\C1yxJ';
|
||||
|
||||
function Encode(s: string): string := s.Select(c -> key[c.code - 32]).JoinToString;
|
||||
|
||||
function Decode(s: string): string := s.Select(c -> Char(key.IndexOf(c) + 32)).JoinToString;
|
||||
|
||||
begin
|
||||
var s := 'The quick brown fox jumps over the lazy dog, who barks VERY loudly!';
|
||||
var enc := Encode(s);
|
||||
Println('Encoded: ' + enc);
|
||||
Println('Decoded: ' + Decode(enc))
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue