| > | currentdir(); |
| (1) |
| > | currentdir("/tmp"); |
| (2) |
| > | currentdir(); |
| (3) |
| > | plainfile:="/home/scott/www/mat331.spr08/problems/424-plain.txt"; |
| (4) |
| > | myFile:=fopen(plainfile, READ); |
| (5) |
| > | line:=readline(myFile); |
| (6) |
| > | line:=readline(myFile); |
| (7) |
| > | line:=readline(myFile); |
| (8) |
| > | line:=readline(myFile); |
| (9) |
| > | line:=readline(myFile); |
| (10) |
| > | fclose(myFile); |
| > | myFile2:=fopen("aux.txt",WRITE); |
| (11) |
| > | writeline(myFile2,"here is some stuff to put in the file. it could be a variable if we want."); |
| (12) |
| > | fclose(myFile2); |
| > |
| > | writeFile:= proc(nameFile::string, outFile::string)
local myFile, myOutput,line; myFile:=fopen(nameFile,READ,TEXT); myOutput:=fopen(outFile, WRITE,TEXT); line:= readline(myFile); while(line<>0)do writeline(myOutput, line); line:=readline(myFile); od; fclose(myFile); fclose(myOutput); end: |
| > | with(StringTools): |
| > | Alphabet:=cat(op(select( IsPrintable, [seq( convert([i],bytes), i=1..255)]))); |
| (13) |
| > |
| > | StringToList := proc(text::string)
global Alphabet; return( [seq( SearchText(text[i], Alphabet) ,i=1..length(text))] ); end: |
| > | ListToString := proc( numlist :: list(posint))
global Alphabet; seq( Alphabet[numlist[i]], i=1..nops(numlist) ); end: |
| > |
| > | AffineEncode := proc( plain::string, shift::integer, a::integer)
local nums,crypt, i; global Alphabet; nums := StringToList(plain); crypt := ListToString( [ seq( modp(a*nums[i] + shift -1, length(Alphabet)) +1, i=1..nops(nums)) ] ); return(cat(crypt)); end: |
| > |
| > | encodeFile:= proc(nameFile::string, outFile::string, shift::integer, a::integer)
local myFile, myOutput,line; myFile:=fopen(nameFile,READ,TEXT); myOutput:=fopen(outFile, WRITE,TEXT); line:= readline(myFile); while(line<>0)do line:=AffineEncode(line,shift,a); writeline(myOutput, line); line:=readline(myFile); od; fclose(myFile); fclose(myOutput); end: |
| > |
| > |
| > |
| > |
| > |
| > |
| > |
| > |
| > | encodeFile(plainfile,"test2.txt",7,13); |
| > | cryptfile:="/home/scott/www/mat331.spr08/problems/424-crypt.txt": |
| > |
| > | mf:=fopen(cryptfile,READ,TEXT); |
| (14) |
| > | line:=readline(mf); |
| (15) |
| > | SearchText(" ",Alphabet); |
| (16) |
| > | SearchText(Y,Alphabet); |
| (17) |
| > | SearchText(e,Alphabet); |
| (18) |
| > | SearchText(D,Alphabet); |
| (19) |
| > |
| > |
| > | msolve({a+shift=58,70*a+shift=37},95); |
| (20) |
| > | AffineEncode(line,modp(-17/41,95),modp(1/41,95)); |
| (21) |
| > |
| > |
| > |
| > |
| > |
| > |
| > |
| > |