08-04-24.mw

> currentdir();
 

/mt/centerport/home/scott/www/mat331.spr08 (1)
 

> currentdir("/tmp");
 

/mt/centerport/home/scott/www/mat331.spr08 (2)
 

> currentdir();
 

/tmp (3)
 

> plainfile:="/home/scott/www/mat331.spr08/problems/424-plain.txt";
 

/home/scott/www/mat331.spr08/problems/424-plain.txt (4)
 

> myFile:=fopen(plainfile, READ);
 

0 (5)
 

> line:=readline(myFile);
 

Alan Mathison Turing,  (23 June 1912 - 7 June 1954) was an English mathematician, logician, and cryptographer.
Alan Mathison Turing,  (23 June 1912 - 7 June 1954) was an English mathematician, logician, and cryptographer.
(6)
 

> line:=readline(myFile);
 

Turing is often considered to be the father of modern computer science. Turing provided an influential formalisation of the concept of the algorithm and computation with the Turing machine. With the ...
Turing is often considered to be the father of modern computer science. Turing provided an influential formalisation of the concept of the algorithm and computation with the Turing machine. With the ...
Turing is often considered to be the father of modern computer science. Turing provided an influential formalisation of the concept of the algorithm and computation with the Turing machine. With the ...
Turing is often considered to be the father of modern computer science. Turing provided an influential formalisation of the concept of the algorithm and computation with the Turing machine. With the ...
Turing is often considered to be the father of modern computer science. Turing provided an influential formalisation of the concept of the algorithm and computation with the Turing machine. With the ...
Turing is often considered to be the father of modern computer science. Turing provided an influential formalisation of the concept of the algorithm and computation with the Turing machine. With the ...
Turing is often considered to be the father of modern computer science. Turing provided an influential formalisation of the concept of the algorithm and computation with the Turing machine. With the ...
Turing is often considered to be the father of modern computer science. Turing provided an influential formalisation of the concept of the algorithm and computation with the Turing machine. With the ...
(7)
 

> line:=readline(myFile);
 

During the Second World War Turing worked at Bletchley Park, Britain's codebreaking centre, and was for a time head of Hut 8, the section responsible for German naval cryptanalysis. He devised a numb...
During the Second World War Turing worked at Bletchley Park, Britain's codebreaking centre, and was for a time head of Hut 8, the section responsible for German naval cryptanalysis. He devised a numb...
During the Second World War Turing worked at Bletchley Park, Britain's codebreaking centre, and was for a time head of Hut 8, the section responsible for German naval cryptanalysis. He devised a numb...
During the Second World War Turing worked at Bletchley Park, Britain's codebreaking centre, and was for a time head of Hut 8, the section responsible for German naval cryptanalysis. He devised a numb...
During the Second World War Turing worked at Bletchley Park, Britain's codebreaking centre, and was for a time head of Hut 8, the section responsible for German naval cryptanalysis. He devised a numb...
(8)
 

> line:=readline(myFile);
 

0 (9)
 

> line:=readline(myFile);
 

0 (10)
 

> fclose(myFile);
 

> myFile2:=fopen("aux.txt",WRITE);
 

0 (11)
 

> writeline(myFile2,"here is some stuff to put in the file. it could be a variable if we want.");
 

74 (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)])));
 

 !?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~" align="center" border="0">
 !?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~" align="center" border="0">
 !?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~" align="center" border="0">
(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);
 

0 (14)
 

> line:=readline(mf);
 

-;~*97Yq`DYZDQb9zY@b~FzY@^~jY$;~*97Y.^HY^Yo^*9Y,^~q*Q*,^9qY*9Yq`DYDmmb~qHY^qY:FDqQ`FD!Y>^~|YqbY(~D^|YID~o^9YQ*,`D~H]Y:;*Fz*97Yb9YQ~!,q^9^F!H*HY.b~|YQ^~~*DzYb;qY*9Y>bF^9zY(!Y
-;~*97Yq`DYZDQb9zY@b~FzY@^~jY$;~*97Y.^HY^Yo^*9Y,^~q*Q*,^9qY*9Yq`DYDmmb~qHY^qY:FDqQ`FD!Y>^~|YqbY(~D^|YID~o^9YQ*,`D~H]Y:;*Fz*97Yb9YQ~!,q^9^F!H*HY.b~|YQ^~~*DzYb;qY*9Y>bF^9zY(!Y
-;~*97Yq`DYZDQb9zY@b~FzY@^~jY$;~*97Y.^HY^Yo^*9Y,^~q*Q*,^9qY*9Yq`DYDmmb~qHY^qY:FDqQ`FD!Y>^~|YqbY(~D^|YID~o^9YQ*,`D~H]Y:;*Fz*97Yb9YQ~!,q^9^F!H*HY.b~|YQ^~~*DzYb;qY*9Y>bF^9zY(!Y
-;~*97Yq`DYZDQb9zY@b~FzY@^~jY$;~*97Y.^HY^Yo^*9Y,^~q*Q*,^9qY*9Yq`DYDmmb~qHY^qY:FDqQ`FD!Y>^~|YqbY(~D^|YID~o^9YQ*,`D~H]Y:;*Fz*97Yb9YQ~!,q^9^F!H*HY.b~|YQ^~~*DzYb;qY*9Y>bF^9zY(!Y
-;~*97Yq`DYZDQb9zY@b~FzY@^~jY$;~*97Y.^HY^Yo^*9Y,^~q*Q*,^9qY*9Yq`DYDmmb~qHY^qY:FDqQ`FD!Y>^~|YqbY(~D^|YID~o^9YQ*,`D~H]Y:;*Fz*97Yb9YQ~!,q^9^F!H*HY.b~|YQ^~~*DzYb;qY*9Y>bF^9zY(!Y
-;~*97Yq`DYZDQb9zY@b~FzY@^~jY$;~*97Y.^HY^Yo^*9Y,^~q*Q*,^9qY*9Yq`DYDmmb~qHY^qY:FDqQ`FD!Y>^~|YqbY(~D^|YID~o^9YQ*,`D~H]Y:;*Fz*97Yb9YQ~!,q^9^F!H*HY.b~|YQ^~~*DzYb;qY*9Y>bF^9zY(!Y
-;~*97Yq`DYZDQb9zY@b~FzY@^~jY$;~*97Y.^HY^Yo^*9Y,^~q*Q*,^9qY*9Yq`DYDmmb~qHY^qY:FDqQ`FD!Y>^~|YqbY(~D^|YID~o^9YQ*,`D~H]Y:;*Fz*97Yb9YQ~!,q^9^F!H*HY.b~|YQ^~~*DzYb;qY*9Y>bF^9zY(!Y
-;~*97Yq`DYZDQb9zY@b~FzY@^~jY$;~*97Y.^HY^Yo^*9Y,^~q*Q*,^9qY*9Yq`DYDmmb~qHY^qY:FDqQ`FD!Y>^~|YqbY(~D^|YID~o^9YQ*,`D~H]Y:;*Fz*97Yb9YQ~!,q^9^F!H*HY.b~|YQ^~~*DzYb;qY*9Y>bF^9zY(!Y
(15)
 

> SearchText(" ",Alphabet);
 

1 (16)
 

> SearchText(Y,Alphabet);
 

58 (17)
 

> SearchText(e,Alphabet);
 

70 (18)
 

> SearchText(D,Alphabet);
 

37 (19)
 

>
 

>
 

> msolve({a+shift=58,70*a+shift=37},95);
 

{shift = 17, a = 41} (20)
 

> AffineEncode(line,modp(-17/41,95),modp(1/41,95));
 

During the Second World War, Turing was a main participant in the efforts at Bletchley Park to break German ciphers. Building on cryptanalysis work carried out in Poland by Marian Rejewski, Jerzy R~~...
During the Second World War, Turing was a main participant in the efforts at Bletchley Park to break German ciphers. Building on cryptanalysis work carried out in Poland by Marian Rejewski, Jerzy R~~...
During the Second World War, Turing was a main participant in the efforts at Bletchley Park to break German ciphers. Building on cryptanalysis work carried out in Poland by Marian Rejewski, Jerzy R~~...
During the Second World War, Turing was a main participant in the efforts at Bletchley Park to break German ciphers. Building on cryptanalysis work carried out in Poland by Marian Rejewski, Jerzy R~~...
During the Second World War, Turing was a main participant in the efforts at Bletchley Park to break German ciphers. Building on cryptanalysis work carried out in Poland by Marian Rejewski, Jerzy R~~...
(21)
 

>
 

>
 

>
 

>
 

>
 

>
 

>
 

>