home *** CD-ROM | disk | FTP | other *** search
- /* -------------------------------------------------------- */
-
- /* encrypt2.rexx */
-
- /* -------------------------------------------------------- */
-
- TEMP='ram:t/temp'
-
- SOURCE_PROMPT='Please enter source file name'
-
- DEST_PROMPT='Please enter destination file name'
-
- KEY_PROMPT='Please enter encryption key file'
-
- SIZE_ERROR='source or key file length error!'
-
- SOURCE_ERROR='cannot open source file'
-
- DESTINATION_ERROR='cannot open destination file'
-
- END_PROMPT='All done!'
-
- /* -------------------------------------------------------- */
-
- say SOURCE_PROMPT; pull source_name
-
- say DEST_PROMPT; pull dest_name
-
- say KEY_PROMPT;parse pull key_name
-
- address command 'list' key_name 'to' TEMP 'nodates nohead'
-
- if Open(t,TEMP,'r') then
-
- do
-
- list_output=Readln(t)
-
- key_length=Word(list_output,2)
-
- Close(t)
-
- if key_length >0 & key_length<65536 then
-
- do
-
- address command 'list' source_name 'to' TEMP 'nodates nohead'
-
- if Open(t,TEMP,'r') then
-
- do
-
- list_output=Readln(t)
-
- source_length=Word(list_output,2)
-
- Close(t)
-
- if source_length>0 then
-
- do
-
- block_count=source_length%key_length
-
- remaining_bytes=source_length-block_count*key_length
-
- call Encrypt()
-
- end /* of source_length >0 ok */
-
- end /* of source_name temp file open ok */
-
- end /* of key_length ok */
-
- else say SIZE_ERROR
-
- end /* of key_name temp file open ok */
-
- exit
-
- /* -------------------------------------------------------- */
-
- Encrypt:
-
- if Open(k,key_name,'r') then
-
- do
-
- key=Readch(k,key_length)
-
- Close(k)
-
- end
-
- if Open(s,source_name,'r') then
-
- do
-
- if Open(d,dest_name,'w') then
-
- do
-
- do i=1 to block_count
-
- source=Readch(s,key_length)
-
- source=BitXOR(source,key)
-
- Writech(d,source)
-
- end /* of handling i'th block */
-
- source=Readch(s,remaining_bytes)
-
- source=BitXOR(source,key)
-
- Writech(d,Left(source,remaining_bytes))
-
- say END_PROMPT
-
- Close(d)
-
- end /* open dest */
-
- else say DESTINATION_ERROR
-
- end /* open source */
-
- else say SOURCE_ERROR
-
- Close(s)
-
- return
-
- /* -------------------------------------------------------- */
-
-