1

I study z/OS and REXX and now have code, which takes public and private keys from MY.DATA.SET (PUBLIC, PRIVATE) and encrypts the message (MSG):

"ALLOC FI(pubkey) DA('MY.DATA.SET(PUBLIC)') SHR REUSE"   
"ALLOC FI(prikey) DA('MY.DATA.SET(PRIVATE)') SHR REUSE"  
"ALLOC FI(msgin)  DA(‘MY.DATA.SET(MSG)') SHR REUSE"  
"ALLOC FI(msgout) DA(*) SHR REUSE"                                      
"EXECIO 1 DISKR pubkey (STEM pub. FINIS"                                
"EXECIO 1 DISKR prikey (STEM pri. FINIS"                                
"EXECIO * DISKR msgin  (STEM msg. FINIS"                                
"EXECIO 0 DISKW msgout (STEM enc_msg. OPEN"                             
enc_msg.1 = pub.1                                                       
"EXECIO 1 DISKW msgout (STEM enc_msg. "                                 
do i=1 to msg.0                                                     
   do j=1 to length(msg.i)                                          
    letter.j = substr(msg.i,j,1)                                    
    encrypt.j = translate(letter.j,pri.1,pub.1)                     
   end                                                              
call write_encrypted_line                                           
end                                                                 
"EXECIO 0 DISKW msgout (FINIS"                                      
"FREE FI(pubkey)"                                                   
"FREE FI(prikey)"                                                   
"FREE FI(msgin)"                                                    
"FREE FI(msgout)"                                                   
exit 0                                                              
write_encrypted_line:                                               
charout = ''                                                        
newchar = ''                                                        
  do j=1 to length(msg.i)                                           
   newchar = encrypt.j                                              
   charout = charout||newchar                                       
  end                                                               
enc_msg.1 = charout                                                 
"EXECIO 1 DISKW msgout (STEM enc_msg. "                             
return                                                              

And I'd like to transfer it to DEsrypting code, which can DEcrypt the encrypted result from above (the result is stored by name MSGEN) to normal text, using, of course, same key-pair. Please, help: what should I change in my encpypring code to make it decrypting? The line

"ALLOC FI(msgin)  DA(‘MY.DATA.SET(MSGEN)') SHR REUSE"

is already changed (MSG->MSGEN)

Thanks for any all help and response!

iceloki
  • 13
  • 2
  • This appears to be a homework question, yes? And what have you tried so far to make it work? – Kevin McKenzie Dec 20 '16 at 20:10
  • Not a homework, but a taskwork. I've read about "AES Clear Key - Generate, Write to CKDS, Encrypt and Decrypt", "AES Secure Key - Generate, Write to CKDS, Encrypt and Decrypt" and a lot about REXX, but nowhere can find such an example. – iceloki Dec 20 '16 at 20:21
  • I think, firstly I must delete string enc_msg.1 = pub.1, am I write? Then to change all "en-" to "de-" (such as: write_decrypted_line, dec_msg, etc.) and then I think it's necessary to change the block DO-END. I tried different things, as "encrypt.j = substr(msg.i,j,1)decrypt.j = translate(encrypt.j,pri.1,pub.1)" – iceloki Dec 20 '16 at 20:27
  • But the output is encrypted yet. If you can explain, where am I wrong, I'll be very happy! – iceloki Dec 20 '16 at 20:29
  • i was such a fool! it's necessary to replace pub.1 and pri.1 in translate, that's it? but the first line stays yet encrypted. how can i fix this, please? – iceloki Dec 20 '16 at 23:27
  • maybe is there a method to EXCLUDE first string from the output? because its public key and it's not for output. – iceloki Dec 21 '16 at 00:22
  • You could DROP the variable e.g. `DROP enc_msg.1` – MikeT Dec 24 '16 at 20:09
  • Thanks a lot for your help!!! – iceloki Jan 19 '17 at 22:06

3 Answers3

0

Without knowing what your keys are I think you need to reverse the keys in your TRANSLATE line.

http://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.ikja300/transl.htm

Here are some examples: 
TRANSLATE('abcdef')                    ->    'ABCDEF'
TRANSLATE('abbc','&','b')              ->    'a&&c'
TRANSLATE('abcdef','12','ec')          ->    'ab2d1f'
TRANSLATE('abcdef','12','abcd','.')    ->    '12..ef'
TRANSLATE('APQRV',,'PR')               ->    'A Q V'
TRANSLATE('APQRV',XRANGE('00'X,'Q'))   ->    'APQ  '
TRANSLATE('4123','abcd','1234')        ->    'dabc'



do i=1 to msg.0                                                     
   do j=1 to length(msg.i)                                          
     letter.j = substr(msg.i,j,1)                                    
     decrypt.j = translate(letter.j,pub.1,pri.1)                     
   end                                                              
   call write_dencrypted_line                                           
end
paulywill
  • 629
  • 10
  • 29
0
/* REXX */                                                            
 /******************************************************************/  
 /**                                                              **/  
 /** Get access to private key, public key, and message           **/  
 /**                                                              **/  
 /******************************************************************/  
 "ALLOC FI(prikey) DA('ZOS.PUBLIC.SECRET.MESSAGES(PRIVATE)') SHR REUSE"
 "ALLOC FI(msgin)  DA('ZOS.PUBLIC.SECRET.MESSAGES(SECRET)') SHR REUSE" 
 /* "ALLOC FI(msgout) DA(*) SHR REUSE" */                              
 /******************************************************************/  
 /**                                                              **/  
 /** In the DECRYPT REXX routine, upon successful decryption      **/  
 /** of ZOS.PUBLIC.SECRET.MESSAGES(SECRET), uncomment msgout      **/  
 /** ALLOC below and comment the msgout ALLOC above               **/  
 /**                                                              **/  
 /******************************************************************/  
 "ALLOC FI(msgout) DA(P3.OUTPUT(#14)) SHR REUSE"                       
 /******************************************************************/  
 /**                                                              **/  
 /** Read private key, public key, and message                    **/  
 /**                                                              **/  
 /******************************************************************/  
 "EXECIO 1 DISKR prikey (STEM pri. FINIS"                              
 "EXECIO * DISKR msgin  (STEM msg. FINIS"                              
 pub.1 = msg.1                                                         
 /* say msg.1 */                                                       
 /******************************************************************/  
 /**                                                              **/  
 /** Parse  encrypted message using (REVERSE) private and public  **/  
 /** key pair to create decrypted message                         **/  
 /**                                                              **/  
 /******************************************************************/  
 do i=2 to msg.0                                                       
    do j=1 to length(msg.i)                                            
     letter.j = substr(msg.i,j,1)                                      
     decrypt.j = translate(letter.j,pub.1,pri.1)                       
    end                                                                
 call write_decrypted_line                                             
-1

This is from IBM Master the Mainframe 2016. It's the training system for the contest. The 2016 contest is already over with.

The stuff about outputting the 1st line can be commented out. The I variable made higher in do i=2 to msg.0 to be like mine "2" to skip the first line of output.

The Public Key is already in the MSG input so just need - pub.1 = msg.1

Delete or comment out the ALLOC, FREE, and EXECIO for Public Key.

It will work if you don't do that, but it's not a complete task.