encryption/decryption functions that take a key (as an integer in 0, 1,2, ... , 25), and a string for plaintext. I try it.. but my key is a constant.. it doesn't change! I use java code.. any ideas?
Well, are you doing the Ceaser Cypher or something like that?
Yes! Is the ceaser cipher!
OK, do you know how to represent a character as a number? Thinking about that will help. Also, do you know how the % operator works? Because it can be very useful for when a number wraps... like if I have something that travles right and goes off the right side of the screen, the % operator can change it so it comes back to the left side. Well, something similar can be done if you want to shoft letters. Say I had an arrray of a to z, with a at postion 0 and z at position 25. Now, lets say I shoft by adding 15 to the value. Well, w + 15 is 22 + 15 = 37! There is no element 37 in the array! But, (22 + 15) % 26 = 11 or k. That should give you some ideas to work with.
Join our real-time social learning platform and learn together with your friends!