> | with(StringTools): |
> | Caesar := proc(plain, shift)
local numlist; numlist:=convert(plain, bytes); convert( [ seq(modp(numlist[i]+shift, 127), i=1..nops(numlist))], bytes); end: |
> | Caesar("Yo' mommy so fat that...",-32); |
(1) |
> | Caesar("Yo' mommy so fat that...",-12); |
(2) |
> | convert("Yo' mommy", bytes); |
(3) |
> | Caesar("Yo' mommy so fat that...",95); |
(4) |
> | Caesar := proc(plain, shift)
local numlist; numlist:=convert(plain, bytes); convert( [ seq(modp(numlist[i]+shift-1, 127)+1, i=1..nops(numlist))], bytes); end: |
> | Caesar("Yo' mommy so fat that...",95); |
(5) |
> | IsPrintable("a"); |
(6) |
> | convert([5],bytes); |
(7) |
> | IsPrintable(convert([5],bytes)); |
(8) |
> | Alphabet:="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_+-=;:' ?<>,\"."; |
(9) |
> | length(Alphabet); |
(10) |
> | SearchText("p", Alphabet); |
(11) |
> | SearchText("a", Alphabet); |
(12) |
> | SearchText(".", Alphabet); |
(13) |
> | SearchText("Howdy", Alphabet); |
(14) |
> | word:="Howdy"; |
(15) |
> | word[1]; |
(16) |
> | word[5]; |
(17) |
> | seq(word[i],i=1..length(word)); |
(18) |
> | StringToList := proc(text)
global Alphabet; return( [seq( SearchText(text[i], Alphabet) ,i=1..length(text))] ); end; |
(19) |
> | StringToList("Howdy"); |
(20) |
> | StringToList(3); |
Error, (in StringToList) invalid arguments for searchtext |
> | StringToList := proc(text::string)
global Alphabet; return( [seq( SearchText(text[i], Alphabet) ,i=1..length(text))] ); end; |
(21) |
> | StringToList(3); |
Error, invalid input: StringToList expects its 1st argument, text, to be of type string, but received 3 |
> | StringToList("3"); |
(22) |
> | ListToString := proc( numlist )
global Alphabet; seq( Alphabet[numlist[i]], i=1..nops(numlist) ); end: |
> | ListToString([3,5,1]); |
(23) |
> | cat(%); |
(24) |
> | ListToString := proc( numlist )
global Alphabet; cat( seq( Alphabet[numlist[i]], i=1..nops(numlist) ) ); end: |
> | ListToString ( [0, -7, 512, 6 ]); |
Error, (in ListToString) invalid range for string subscript |
> | ListToString ( "Henry"); |
Error, (in ListToString) invalid string subscript selector |
> | ListToString := proc( numlist :: list(posint))
global Alphabet; cat( seq( Alphabet[numlist[i]], i=1..nops(numlist) ) ); end: |
> | ListToString ( "Henry"); |
Error, invalid input: ListToString expects its 1st argument, numlist, to be of type list(posint), but received Henry |
> | ListToString ( [0, -7, 512, 6 ]); |
Error, invalid input: ListToString expects its 1st argument, numlist, to be of type list(posint), but received [0, -7, 512, 6] |
> | ListToString ( [1, 7, 512, 6 ]); |
(25) |
> | Alphabet; |
(26) |
> | Julius := proc( plain::string, shift::integer)
local nums,crypt, i; global Alphabet; nums := StringToList(plain); crypt := ListToString( [ seq(nums[i] + shift, i=1..nops(nums)) ] ); return(crypt); end: |
> | Julius("hide me. Please, I'm SCARED!", 1); |
(27) |
> | Julius(%, -1); |
(28) |
> | Julius("hide me. Please, I'm SCARED!", 75); |
(29) |
> | Julius(%, -75); |
(30) |
> | Julius := proc( plain::string, shift::integer)
local nums,crypt, i; global Alphabet; nums := StringToList(plain); crypt := ListToString( [ seq( modp(nums[i] + shift -1, length(Alphabet)) +1, i=1..nops(nums)) ] ); return(crypt); end: |
> | Julius("hide me. Please, I'm SCARED!", 75); |
(31) |
> | Julius(%, -75); |
(32) |
> | Alphabet; |
(33) |
> | Julius(" I have heard the mermaids singing, each to each.
I do not think they will sing to me.", 0); |
(34) |
> | SearchText("
",Alphabet); |
(35) |
> | Julius(" I have heard the mermaids singing, each to each.
I do not think they will sing to me.", 1); |
(36) |
> | StringToList("secret"); |
(37) |
> |