이 코드는 일반 텍스트를 가져 와서 512 비트 이진 문자열로 변환합니다. 다음, 문제가 하나이며 그 중 나는 진수 문자열의 8 비트 문자열의 각 32 비트 조각을 설정하고 싶지만, 그 부분은 나에게 java.lang.NumberFormatException
16 진수 문자열에서 16 진수 문자열 java
// ----- Turning the message to bits
byte[] binaryS = s.getBytes("UTF-8");
String mesInBinary = "";
for (byte b : binaryS) {
mesInBinary += '0' + Integer.toBinaryString(b);
}
// ----- Message padding & Pre-Processing
// Binary representation of the length of the message in bits
String mesBitLength = Integer.toBinaryString(mesInBinary.length());
// We need the size of the message in 64-bits, so we'll
// append zeros to the binary length of the message so
// we get 64-bit
String appendedZeros = "";
for (int i = 64 - mesBitLength.length() ; i > 0 ; i--)
appendedZeros += '0';
// Calculating the k zeros to append to the message after
// the appended '1'
int numberOfZeros = (448 - (mesInBinary.length() + 1)) % 512;
// Append '1' to the message
mesInBinary += '1';
// We need a positive k
while (numberOfZeros < 0)
numberOfZeros += 512;
for (int i = 1 ; i <= numberOfZeros ; i++)
mesInBinary += '0';
// append the message length in 64-bit format
mesInBinary += appendedZeros + mesBitLength;
System.out.println(mesInBinary);
// ----- Parsing the padded message
// Breaking the message to 512-bit pieces
// And each piece, to 16 32-bit word blocks
String[] chunks = new String[mesInBinary.length()/512];
String[] words = new String[64 * chunks.length];
for (int i = 0 ; i < chunks.length ; i++) {
chunks[i] = mesInBinary.substring((512 * i), (512 * (i + 1)));
// Break each chunk to 16 32-bit blocks
for (int j = 0 ; j < 16 ; j++) {
words[j] = Long.toHexString(Long.parseLong(chunks[i].substring((32 * j), (32 * (j + 1)))));
}
}
마지막 코드 라인을 제공 I 집행을 해. 어떤 제안?
는
코드의 마지막 행은이 '}'... –
신은 I가 [I]을 ((32 *의 J를 .substring) 즉 [J] = Long.toHexString (Long.parseLong (청크를 의미 알고있다 (32 * (j + 1)))))); – DanielY