Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
6 views2 pages

SHA1

The document contains a Java program that computes the SHA-1 hash of user input and writes the result to a file. It includes methods for reading input, generating the hash, and converting byte arrays to hexadecimal format. Additionally, there are some questions related to cryptography and bit calculations at the end.

Uploaded by

49ry27nf9b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

SHA1

The document contains a Java program that computes the SHA-1 hash of user input and writes the result to a file. It includes methods for reading input, generating the hash, and converting byte arrays to hexadecimal format. Additionally, there are some questions related to cryptography and bit calculations at the end.

Uploaded by

49ry27nf9b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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

You might also like