Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
|
|
@ -61,15 +61,15 @@ extension encryptOp
|
|||
|
||||
public program()
|
||||
{
|
||||
console.printLine("Original text :",TestText);
|
||||
Console.printLine("Original text :",TestText);
|
||||
|
||||
var encryptedText := TestText.encrypt(Key);
|
||||
|
||||
console.printLine("Encrypted text:",encryptedText);
|
||||
Console.printLine("Encrypted text:",encryptedText);
|
||||
|
||||
var decryptedText := encryptedText.decrypt(Key);
|
||||
|
||||
console.printLine("Decrypted text:",decryptedText);
|
||||
Console.printLine("Decrypted text:",decryptedText);
|
||||
|
||||
console.readChar()
|
||||
Console.readChar()
|
||||
}
|
||||
|
|
|
|||
20
Task/Caesar-cipher/Pluto/caesar-cipher.pluto
Normal file
20
Task/Caesar-cipher/Pluto/caesar-cipher.pluto
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
local function caesar(s, k, e=true)
|
||||
-- Parameters: s (string), k (key)
|
||||
-- e (true=encode, false=decode)
|
||||
if !e do k=-k end
|
||||
local out = ""
|
||||
for i = 1, #s do
|
||||
local c = s[i]
|
||||
if c:islower() then
|
||||
out ..= string.char((c:byte() - 97 + k) % 26 + 97)
|
||||
elseif c:isupper() then
|
||||
out ..= string.char((c:byte() - 65 + k) % 26 + 65)
|
||||
else
|
||||
out ..= c
|
||||
end
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
print(caesar("The quick brown fox jumps over the lazy dog.", 3))
|
||||
print(caesar("Wkh txlfn eurzq ira mxpsv ryhu wkh odcb grj.", 3, false))
|
||||
25
Task/Caesar-cipher/Rhombus/caesar-cipher.rhombus
Normal file
25
Task/Caesar-cipher/Rhombus/caesar-cipher.rhombus
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#lang rhombus/static
|
||||
|
||||
import lib("racket/base.rkt") expose:
|
||||
#{string->list} as string_to_list
|
||||
#{list->string} as list_to_string
|
||||
modulo
|
||||
|
||||
fun make_rot13_char(key :: Int):
|
||||
fun (char :: Char):
|
||||
let char_int = char.to_int()
|
||||
fun rot13_by_case(char_int, a_char :: Char) :: Int :
|
||||
modulo(char_int - a_char.to_int() + key, 26) + a_char.to_int()
|
||||
if char.is_alphabetic():
|
||||
| if char.is_lowercase():
|
||||
| Char.from_int(rot13_by_case(char_int, Char"a"))
|
||||
| Char.from_int(rot13_by_case(char_int, Char"A"))
|
||||
| char
|
||||
|
||||
fun rot13_string(str :: String, key :: Int) :: String :
|
||||
let chars :: PairList = string_to_list(str)
|
||||
let rot13_char = make_rot13_char(key)
|
||||
let str :: MutableString = list_to_string(chars.map(rot13_char))
|
||||
str.snapshot()
|
||||
|
||||
rot13_string("Hello, World!", 14) // Output: "Vszzc, Kcfzr!""
|
||||
Loading…
Add table
Add a link
Reference in a new issue