Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
58
Task/Caesar-cipher/Cubescript/caesar-cipher-1.cube
Normal file
58
Task/Caesar-cipher/Cubescript/caesar-cipher-1.cube
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
alias modn [ mod (+ (mod $arg1 $arg2) $arg2) $arg2 ]
|
||||
//Cubescript's built-in mod will fail on negative numbers
|
||||
|
||||
alias cipher [
|
||||
push alpha [
|
||||
"A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
|
||||
"a b c d e f g h i j k l m n o p q r s t u v w x y z"
|
||||
] [ push chars [] [
|
||||
loop i (strlen $arg1) [
|
||||
looplist n $alpha [
|
||||
if (! (listlen $chars)) [
|
||||
alias chars (? (> (listindex $n (substr $arg1 $i 1)) -1) $n [])
|
||||
]
|
||||
]
|
||||
alias arg1 (
|
||||
concatword (substr $arg1 0 $i) (
|
||||
? (> (listindex $chars (substr $arg1 $i 1)) -1) (
|
||||
at $chars (
|
||||
modn (+ (
|
||||
listindex $chars (substr $arg1 $i 1)
|
||||
) $arg2) (listlen $chars)
|
||||
)
|
||||
) (substr $arg1 $i 1)
|
||||
) (substr $arg1 (+ $i 1) (strlen $arg1))
|
||||
)
|
||||
alias chars []
|
||||
]
|
||||
] ]
|
||||
result $arg1
|
||||
]
|
||||
|
||||
alias decipher [
|
||||
push alpha [
|
||||
"A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
|
||||
"a b c d e f g h i j k l m n o p q r s t u v w x y z"
|
||||
] [ push chars [] [
|
||||
loop i (strlen $arg1) [
|
||||
looplist n $alpha [
|
||||
if (! (listlen $chars)) [
|
||||
alias chars (? (> (listindex $n (substr $arg1 $i 1)) -1) $n [])
|
||||
]
|
||||
]
|
||||
alias arg1 (
|
||||
concatword (substr $arg1 0 $i) (
|
||||
? (> (listindex $chars (substr $arg1 $i 1)) -1) (
|
||||
at $chars (
|
||||
modn (- (
|
||||
listindex $chars (substr $arg1 $i 1)
|
||||
) $arg2 ) (listlen $chars)
|
||||
)
|
||||
) (substr $arg1 $i 1)
|
||||
) (substr $arg1 (+ $i 1) (strlen $arg1))
|
||||
)
|
||||
alias chars []
|
||||
]
|
||||
] ]
|
||||
result $arg1
|
||||
]
|
||||
4
Task/Caesar-cipher/Cubescript/caesar-cipher-2.cube
Normal file
4
Task/Caesar-cipher/Cubescript/caesar-cipher-2.cube
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
>>> cipher "The Quick Brown Fox Jumps Over The Lazy Dog." 5
|
||||
> Ymj Vznhp Gwtbs Ktc Ozrux Tajw Ymj Qfed Itl.
|
||||
>>> decipher "Ymj Vznhp Gwtbs Ktc Ozrux Tajw Ymj Qfed Itl." 5
|
||||
> The Quick Brown Fox Jumps Over The Lazy Dog.
|
||||
Loading…
Add table
Add a link
Reference in a new issue