Suppose there is one message and the user enters a number/key (3 digit number). Now the data need to be encrypted in a form that is unreadable and if the number is entered again then data need to be decrypted again back to the readable form.
Logic -
Extract the first and last digit of the number. For example, the first digit is 3 and last digit is 4 replace the character at 3rd position with 4th and 4th position with the 3rd position. Then multiply the first digit and last digit with 2 and continue the same operation of replacing the characters until any value whether its first or last exceeds the message length.
Note - This process can be continued as many times, the more the times the steps are repeated more difficult it will be to get the original message.
After doing this all the spaces can be replaces with a special character.
The decryption process is totally reverse. First replace all the special character with the spaces (the special character which was used to replace the space before). Scan the number/key again because until the same number/key will be entered, the message need not to be decrypted. After that extract the first and last digit multiply it with 2 until the value of any digit whether first number and last number is greater than the message length and the previous value of first and last digit before multiplying it with 2 must be stored (previous value means that if corresponding value of first and last digit are (4.2),(8,4),(16,8) so for (16,8) (8,4) must be kept). and now replace the characters at those particular positions (at previous value that was kept where the value exceeded the message length) and then divide the values(first and last digit) by 2 (during encryption we multiplied them with 2) and continue the process until the value of first and last digit is not same as the first and last digit of the number being scanned. You again got the decrypted data.
Note - The message length should be even, if it is not convert it to even first by adding a space at the last position.
No comments:
Post a Comment