View previous topic :: View next topic
|
Author |
Message |
pkmurali Warnings : 1 Active User
Joined: 15 Dec 2005 Posts: 271
|
|
|
|
Dear all,
I have to write an rexx program to encrpyt a sequential file. Using similar logic mentioned in the below code.
Code: |
/********REXX*******/
say 'The no to be encrypt is 1101:'
a=1101
say 'The pwd to be embeded is 1001:'
pwd=1001
c=bitxor(a,pwd)
say 'The encrypted value is:' c
d=bitxor(c,pwd)
say 'The decrypted value is:' d
exit
|
I got the decrypted value as 1101. But when i get the character from user(using pull) after converting character to hex and hex to binary then i xor with pwd i am not able to decrypt the data. I am not getting the original input from decrption.
The below is the code.
Please let me know how to fix this issue. Also is it possible to encrypt a file using above logic.
Code: |
/******REXX******/
Say 'Enter the word to be encrypted:'
Pull a
Say 'Enter the pwd for encryption(1-8):'
Pull pwd
b=c2x(a)
c=x2b(b)
e=c2x(pwd)
f=x2b(e)
encrypt=bitxor(c,f)
Say 'encrypted word is:' encrypt
decrypt=bitxor(encrypt,pwd)
say 'decrpyted:' decrypt
exit
|
|
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Code: |
decrypt = bitxor(encrypt,b_pwd)
say 'decrypted:' x2c(b2x(decrypt)) |
b_pwd is the same as 'f' in your code (why can you not use meaningful names?).
The result is in upper case because you did not PARSE your PULL. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2023 Location: USA
|
|
|
|
As Nic mentioned above, you need RTFM
PULL ... is equivalent to PARSE UPPER PULL ...
In order to work with mixed case data you need to use PARSE PULL ...
If only you tried to trace what you're doing, you would discover this issue immediately. Instead of asking the forum.
RTFM, RTFM, and RTFM, forever(?) |
|
Back to top |
|
|
|