C:\Users\M\Documents\NetBeansProjects\SHA1\src\sha1\SHA1.
java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package sha1;
import java.io.FileWriter;
import java.security.*;
import java.util.Scanner;
public class SHA1 {
public static void main(String[] a) {
try (FileWriter fr = new FileWriter("txt2")){
// s = new Scanner(new File("C:\\Users\\M\\Desktop\\txt1.txt"));
Scanner s = new Scanner(System.in);
MessageDigest md = MessageDigest.getInstance("SHA1");
System.out.print("Enter pt: ");
String input = s.nextLine();
md.update(input.getBytes());
byte[] output = md.digest();
System.out.println();
fr.write("SHA1(\"" + input + "\") = " + bytesToHex(output));
} catch (Exception e) {
System.out.println("Exception: " + e);
}
}
public static String bytesToHex(byte[] b) {
char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
StringBuffer buf = new StringBuffer();
for (int j = 0; j < b.length; j++) {
buf.append(hexDigit[(b[j] >> 4) & 0x0f]);
buf.append(hexDigit[b[j] & 0x0f]);
}
return buf.toString();
}
}
Q1:
2^128 -1 bits
Q2:
80 * 64 = 5120 bits
Q3:
K from fractional parts of (primes)^1/3