43 lines
974 B
Plaintext
43 lines
974 B
Plaintext
lowers = ['a','z']
|
|
uppers = ['A','Z']
|
|
function void caesar_encode(message:ptr key:uint) {
|
|
len = strlen$ message
|
|
for uint [0u,len) with index {
|
|
temp = deref_ubyte$ + message index
|
|
if in temp lowers {
|
|
temp = + temp key// shift lowercase letters
|
|
if > temp 'z' {
|
|
temp = - temp 26ub
|
|
} ;
|
|
} {
|
|
if in temp uppers {
|
|
temp = + temp key// shift uppercase letters
|
|
if > temp 'Z' {
|
|
temp = - temp 26ub
|
|
} ;
|
|
} ;//don't shift other characters
|
|
}
|
|
put_ubyte$ + message index temp
|
|
}
|
|
}
|
|
function void caesar_decode(message:ptr key:uint) {
|
|
caesar_encode$ message - 26u key
|
|
}
|
|
|
|
key = 1u
|
|
response = malloc$ 256u
|
|
puts$ "plaintext: "
|
|
getline$ response
|
|
caesar_encode$ response key
|
|
puts$ "cyphertext: "
|
|
puts$ response
|
|
putln$
|
|
caesar_decode$ response key
|
|
puts$ "decoded: "
|
|
puts$ response
|
|
free$ response
|
|
free$ lowers // ranges are objects and must be freed
|
|
free$ uppers
|
|
|
|
//this compiles with only 6 warnings!
|