Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
30
Task/Caesar-cipher/Jq/caesar-cipher.jq
Normal file
30
Task/Caesar-cipher/Jq/caesar-cipher.jq
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
def encrypt(key):
|
||||
. as $s
|
||||
| explode as $xs
|
||||
| (key % 26) as $offset
|
||||
| if $offset == 0 then .
|
||||
else reduce range(0; length) as $i ( {chars: []};
|
||||
$xs[$i] as $c
|
||||
| .d = $c
|
||||
| if ($c >= 65 and $c <= 90) # 'A' to 'Z'
|
||||
then .d = $c + $offset
|
||||
| if (.d > 90) then .d += -26 else . end
|
||||
else if ($c >= 97 and $c <= 122) # 'a' to 'z'
|
||||
then .d = $c + $offset
|
||||
| if (.d > 122)
|
||||
then .d += -26
|
||||
else .
|
||||
end
|
||||
else .
|
||||
end
|
||||
end
|
||||
| .chars[$i] = .d )
|
||||
| .chars | implode
|
||||
end ;
|
||||
|
||||
def decrypt(key): encrypt(26 - key);
|
||||
|
||||
"Bright vixens jump; dozy fowl quack."
|
||||
| .,
|
||||
(encrypt(8)
|
||||
| ., decrypt(8) )
|
||||
Loading…
Add table
Add a link
Reference in a new issue