> | with(StringTools): |
> | convert("Word",bytes); |
(1) |
> | convert([87,111,111,111],bytes); |
(2) |
> | for i from 1 to 40 do
if ( IsPrintable(convert([i], bytes) )) then print(i); fi; od; |
(3) |
> |
seq( convert([i],bytes), i=1..255); |
(4) |
> | select( IsPrintable, [seq( convert([i],bytes), i=1..255)]); |
", "?", "@", "A", "B", "C", "D", "E", "F", "G",..." align="center" border="0"> ", "?", "@", "A", "B", "C", "D", "E", "F", "G",..." align="center" border="0"> ", "?", "@", "A", "B", "C", "D", "E", "F", "G",..." align="center" border="0"> ", "?", "@", "A", "B", "C", "D", "E", "F", "G",..." align="center" border="0"> |
(5) |
> | Alphabet:=cat(op(select( IsPrintable, [seq( convert([i],bytes), i=1..255)]))); |
?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~" align="center" border="0"> ?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~" align="center" border="0"> ?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~" align="center" border="0"> |
(6) |
> | length(Alphabet); |
(7) |
> | StringToList := proc(text)
global Alphabet; return( [seq( SearchText(text[i], Alphabet) ,i=1..length(text))] ); end: ListToString := proc( numlist ) global Alphabet; seq( Alphabet[numlist[i]], i=1..nops(numlist) ); end: |
> | 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: |
> | Vignere := proc( plain::string, shifts::list(integer))
local nums,crypt, i, L; global Alphabet; L := nops(shifts); nums := StringToList(plain); crypt := ListToString( [ seq(nums[i] + shifts[modp(i,L)+1], i=1..nops(nums)) ] ); return(crypt); end: |
> | Vignere("abcd", [4,3,2,1]); |
(8) |
> | Vignere := proc( plain::string, shifts::list(integer))
local nums,crypt, i, L; global Alphabet; L := nops(shifts); nums := StringToList(plain); crypt := cat( ListToString( [ seq(nums[i] + shifts[modp(i-1,L)+1], i=1..nops(nums)) ] )); return(crypt); end: |
> | Vignere("abcd", [4,3,2,1]); |
(9) |
> | Vignere(%, [-4,-3,-2,-1]); |
(10) |
> | unVignere := proc( plain::string, shifts::list(integer))
local nums,crypt, i, L; global Alphabet; L := nops(shifts); nums := StringToList(plain); crypt := cat( ListToString( [ seq(nums[i] - shifts[modp(i-1,L)+1], i=1..nops(nums)) ] )); return(crypt); end: |
> | unVignere("eeee",[4,3,2,1]); |
(11) |
> |
> |
> |
> | myrand:=rand(95); |
(12) |
> | myrand(); |
(13) |
> | myrand(); |
(14) |
> | myrand(); |
(15) |
> | ?rand |
> | seq(myrand(),i=1..200); |
(16) |
> | seq(myrand(),i=1..200); |
(17) |
> | randomize(2); |
(18) |
> | seq(myrand(),i=1..20); |
(19) |
> | randomize(2); |
(20) |
> | seq(myrand(),i=1..20); |
(21) |
> | OneTimePad := proc( plain::string, seed::integer)
local nums,crypt, i, myrand, L; global Alphabet; L:=length(Alphabet); myrand := rand(1..L); randomize(seed); nums := StringToList(plain); crypt := cat(ListToString( [ seq( modp(nums[i] + myrand()-1, L)+1, i=1..nops(nums)) ] )); return(crypt); end: |
> | OneTimePad("ho ho ho", 7); |
(22) |
> | UnTimePad := proc( plain::string, seed::integer)
local nums,crypt, i, myrand, L; global Alphabet; L:=length(Alphabet); myrand := rand(1..L); randomize(seed); nums := StringToList(plain); crypt := cat(ListToString( [ seq( modp(nums[i] - myrand()-1, L)+1, i=1..nops(nums)) ] )); return(crypt); end: |
> | OneTimePad("ho ho ho", 7); |
(23) |
> | UnTimePad(%, 7); |
(24) |
> |