Skip to content

Instantly share code, notes, and snippets.

@AwaisKing
Created October 17, 2017 06:28
Show Gist options
  • Save AwaisKing/888c6085977b69580d9e6ada3efb04a4 to your computer and use it in GitHub Desktop.
Save AwaisKing/888c6085977b69580d9e6ada3efb04a4 to your computer and use it in GitHub Desktop.
Some kind of file hash generation
package awais;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
File file = new File("C:\\Users\\AWAiS\\Desktop\\test");
FileInputStream is = new FileInputStream(file);
byte[] chunk = new byte[33];
int[] p1 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int[] p2 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
char[] hash = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
while (is.read(chunk) != -1) {
for (int i=0; i<chunk.length; i++) {
p1[i] += (int) chunk[i];
p2[i] += (int) chunk[i];
}
}
for (int i=0; i<p2.length/2; i++) {
int temp = p2[i];
p2[i] = p2[p2.length-1-i];
p2[p2.length-1-i] = temp;
}
for (int i=0; i<hash.length; i++) hash[i] = (char) (p1[i] + p2[i]);
for (int i=0; i<hash.length; i++) System.out.print((int)hash[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment