Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
How do I convert input string to hash and back to original string in console window at the same time in c#


What I have tried:

write a program to convert input string to hash and back to original string in console window at the same time in c#
Posted
Updated 14-Dec-16 10:10am

You can't.
Hashing is not encryption: encryption can be reversed, provided you know the algorithm and key used for encryption. Hashing cannot: it is the process of producing a number from a string of text. The hash is normally considerably smaller than the original text and is generated in such a way that it is unlikely that some other text will produce the same hash value. But because most of the original data it "thrown away", it is not possible to reverse the process and get back to the original string.
If you have four numbers: 10, 14, 18, 49 you can "encrypt" them by adding the index multiplied by e a "key value" to each number. If we have a key of 2, the the encrypted data would be 10, 16, 22, 55 and you can decrypt that back to the original by reversing the process. (It'd be a rubbish encryption algorithm, but...)
The hash version might work by adding each value together to produce 91. But you can;'t get back to the original from just 91: it could be 1, 1, 1, 88, or 1, 1, 2, 87, or ....
 
Share this answer
 
Quote:
How do I convert input string to hash and back to original string
Short answer: you don't.
Hashing is a one way ticket, there is no return.
Encryption works both ways.

General principles: Your bank account number is made of the real account number and a key (a couple digits).
The key is a hash code calculated from the account number, and together, they verify a mathematical property. The hash is easily computed and verified, but not the reverse.
 
Share this answer
 
I am beginner in programming world. Ok I learn about hashing today. Anyway, how can we do encrypt and decrypt the given string in same console window?
 
Share this answer
 
Comments
[no name] 14-Dec-16 15:02pm    
"beginner in programming", learn how to use google. There must be thousands of encrypt/decrypt examples for you to look at if you just go look for them.
Patrice T 14-Dec-16 15:50pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.
and then delete this solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900