From 1702b10d2797fbfec3a703e25f98fa0076a628f8 Mon Sep 17 00:00:00 2001 From: k0rrluna Date: Sun, 16 Feb 2025 20:33:56 +0300 Subject: [PATCH] cryptopals --- cryptopals/set1/challenge1/hexToBase64.java | 22 +++++++++++++ cryptopals/set1/challenge2/fixedXor.java | 32 +++++++++++++++++++ .../set1/challenge3/singleByteXORCipher.java | 25 +++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 cryptopals/set1/challenge1/hexToBase64.java create mode 100644 cryptopals/set1/challenge2/fixedXor.java create mode 100644 cryptopals/set1/challenge3/singleByteXORCipher.java diff --git a/cryptopals/set1/challenge1/hexToBase64.java b/cryptopals/set1/challenge1/hexToBase64.java new file mode 100644 index 0000000..13c78d9 --- /dev/null +++ b/cryptopals/set1/challenge1/hexToBase64.java @@ -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); + } + +} diff --git a/cryptopals/set1/challenge2/fixedXor.java b/cryptopals/set1/challenge2/fixedXor.java new file mode 100644 index 0000000..06a19c9 --- /dev/null +++ b/cryptopals/set1/challenge2/fixedXor.java @@ -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; +} + +} diff --git a/cryptopals/set1/challenge3/singleByteXORCipher.java b/cryptopals/set1/challenge3/singleByteXORCipher.java new file mode 100644 index 0000000..753a50d --- /dev/null +++ b/cryptopals/set1/challenge3/singleByteXORCipher.java @@ -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]); + } + +} + + + } + +}