Bob believes that he has come up with a nifty hash function. He assigns a numeri
ID: 3916041 • Letter: B
Question
Bob believes that he has come up with a nifty hash function. He assigns a numeric value VChar to each letter in the alphabet equal to the letter’s position in the alphabet, i.e., VA = 1, VB = 2, …, VZ = 26. For a message, he calculates the hash value H = (VChar 1 x VChar 2 x VChar 3 …x VChar N) mod (26). Bob uses this function to send a one-word message, Koinonia to his supervisor Bill, along with his calculated hash value for the message. Alice is able to intercept the message and generates an alternative message that has a hash value that collides with Bob’s original hash value. Give definition and properties of the hash function. Show a message that Alice may have used to spoof Bob’s message and demonstrate that its hash value collides with Bob’s original hash.
Explanation / Answer
//Hashfun.java
import java.util.*;
public class Hashfun
{
public static long hashfun(String t) //hashfun which accepts the string and retuns hashvlaue
{
int l=t.length();
long hashvalue=1;
for(int i=0;i<l;i++)
{
int temp= t.charAt(i)-64;
hashvalue*=temp;
}
return(hashvalue);
}//hashfunc
public static void main(String ar[])
{
System.out.print("The Alice code value for Bob's code is "+hashfun("Aplle"));
}
}//class closing
output :
The Alice code value for Bob's code is 3438336
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.