cryptopals
This commit is contained in:
parent
aea61f2076
commit
1702b10d27
22
cryptopals/set1/challenge1/hexToBase64.java
Normal file
22
cryptopals/set1/challenge1/hexToBase64.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import java.util.Base64;
|
||||||
|
import java.util.HexFormat;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class hexToBase64 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
HexFormat hex = HexFormat.of();
|
||||||
|
Scanner scan = new Scanner(System.in);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("Enter hex!");
|
||||||
|
String hexString = scan.next();
|
||||||
|
byte[] byteString = HexFormat.of().parseHex(hexString);
|
||||||
|
String convertedHex = Base64.getEncoder().encodeToString(byteString);
|
||||||
|
scan.close();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(convertedHex);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
32
cryptopals/set1/challenge2/fixedXor.java
Normal file
32
cryptopals/set1/challenge2/fixedXor.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.HexFormat;
|
||||||
|
|
||||||
|
public class fixedXor {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner scan = new Scanner(System.in);
|
||||||
|
System.out.println("Enter byte string!");
|
||||||
|
String byte1 = scan.next();
|
||||||
|
String byte2 = scan.next();
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(HexFormat.of().formatHex(fixedXOR(byte1, byte2)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] fixedXOR(String byte1, String byte2) {
|
||||||
|
byte[] byteS1 = HexFormat.of().parseHex(byte1);
|
||||||
|
byte[] byteS2 = HexFormat.of().parseHex(byte2);
|
||||||
|
|
||||||
|
if (byteS1.length != byteS2.length) {
|
||||||
|
throw new IllegalArgumentException("Not same!");
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] result = byteS1;
|
||||||
|
for (int t = 0; t < byteS1.length; t++) {
|
||||||
|
result[t] = (byte) (byteS1[t] ^ byteS2[t]);
|
||||||
|
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
25
cryptopals/set1/challenge3/singleByteXORCipher.java
Normal file
25
cryptopals/set1/challenge3/singleByteXORCipher.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import java.util.HexFormat;
|
||||||
|
|
||||||
|
|
||||||
|
public class singleByteXORCipher {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String hexS = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736";
|
||||||
|
byte[] byteS = HexFormat.of().parseHex(hexS);
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
String crypted = "";
|
||||||
|
int t = 0;
|
||||||
|
byte max = 0x00;
|
||||||
|
|
||||||
|
for(byte b = 0x00; b <= 0xFF; b++){
|
||||||
|
String Tcrypted = "";
|
||||||
|
for(int a = 0; a < hexS.length; a++) {
|
||||||
|
Tcrypted = (byte) (b ^ hexS[a]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user