Reputation: 23
Hiii,I need to do the opposite of what my hash method does, I want a number to convert it to a string, unlike my other method.
I need you to do it in the same way coding as decoding
Upvotes: 0
Views: 193
Reputation: 36
I think that you are trying to implement the Vigenère cipher.
I have fixed your code for executing the two functions (hash
and hash2
) and I have noticed that hash("javaguay")
returns the long number 2485697837967351
and then hash2(2485697837967351L)
returns yaugavaj
, the reverse string that you want.
A quick response could be the next, but I think you must fix your algorithm.
Add these lines to the end hash2
function:
String res2 = "";
for (int i = res.length() -1; i >=0; i--) {
res2 += res.charAt(i);
}
return res2;
Upvotes: 0
Reputation: 394026
That would only be possible if there was a 1 to 1 mapping between String
s and long
s. Since there are 264 possible long values, and many many more possible String
values (even if you limit yourself to String
s of 64 characters, there are still K64 of them, where K is the number of possible unique characters), there cannot be a method that reverses your long hash(String c)
method for all possible String
s.
Upvotes: 2