Cryptography Reference
In-Depth Information
action to take if the file already exists. In this case the user can choose between
overwriting the existing file, aborting the process or choosing a new file name. The
output of the function is either an error message if the operation is aborted or a file
name:
Now, to write a list of bytes to a file, we have to convert bytes (integers in the
0..255 range) to integers of type integer[1]. One would like to use the function
mods(-, 256) but this function does not map the 0..255 range to the -128..127
range but to the -127..128 range instead. This problem is easily solved since,
after applying mods(-,256) , it suffices to take care of converting the 128 byte
to -128 instead of keeping its original value. We do it by using a slight
modification of this function, namely the function x ! mods(x+1,256)-1 .In
order to speed up this process, we build a table to convert bytes to integers in the
integer[1] range:
The function that writes the byte list to a file is bytestofile below. The input
is the list of bytes to be written to the file, the file name (given as a string), a
Boolean-valued parameter called filecheck and a parameter called
logoutput . If the value true is passed to filecheck , the function calls
checkfile to check whether a file with the same name exists in the current
directory and eventually prompts the user about which action to take. On the other
hand, the value of logoutput can be none , file or terminal , and it specifies
whether logging information (indicating the number of bytes written and the name
of the file) is provided and, in this case, whether it is written to a file or to the
terminal (i.e., printed on the screen).
Search WWH ::




Custom Search