The Key to Cryptography: Difference between revisions
		
		
		
		Jump to navigation
		Jump to search
		
imported>Kmk21  Created page with "This problem asks us to rotate the characters in a string by the value of the character in the same position in a key string.  If you use ascii math and char arrays this is ea..."  | 
			
(No difference) 
 | 
Revision as of 22:28, 2 November 2017
This problem asks us to rotate the characters in a string by the value of the character in the same position in a key string.
If you use ascii math and char arrays this is easy.
encrypt[i] = (((plain[i] - 'A') + (key[i] - 'A')) %26) + 'A' plain[i] = (((encrypt[i] - 'A') - (key[i] - 'A') + 26) % 26) + 'A'
be sure to add 26 when modding after doing a subtraction.