From ad2832757e015fa05ab9855e0d4d661fe6026d2a Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 18 Oct 2020 21:43:55 +0200 Subject: [PATCH] inital commit --- .idea/.gitignore | 8 + .idea/description.html | 1 + .idea/encodings.xml | 6 + .idea/misc.xml | 9 + .idea/modules.xml | 8 + .idea/project-template.xml | 3 + CTS_Solver.iml | 12 + .../CTS_Solver/tech/loedige/Main.class | Bin 0 -> 2073 bytes out/production/CTS_Solver/util/Dump.class | Bin 0 -> 5431 bytes .../util/IllegalHexDumpException.class | Bin 0 -> 380 bytes src/tech/loedige/Main.java | 35 +++ src/util/Dump.java | 215 ++++++++++++++++++ src/util/IllegalHexDumpException.java | 15 ++ 13 files changed, 312 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/description.html create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/project-template.xml create mode 100644 CTS_Solver.iml create mode 100644 out/production/CTS_Solver/tech/loedige/Main.class create mode 100644 out/production/CTS_Solver/util/Dump.class create mode 100644 out/production/CTS_Solver/util/IllegalHexDumpException.class create mode 100644 src/tech/loedige/Main.java create mode 100644 src/util/Dump.java create mode 100644 src/util/IllegalHexDumpException.java diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..4aa91ea --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/description.html b/.idea/description.html new file mode 100644 index 0000000..db5f129 --- /dev/null +++ b/.idea/description.html @@ -0,0 +1 @@ +Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..ab2dc53 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..04e7f92 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..5cb698f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/project-template.xml b/.idea/project-template.xml new file mode 100644 index 0000000..d57a956 --- /dev/null +++ b/.idea/project-template.xml @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/CTS_Solver.iml b/CTS_Solver.iml new file mode 100644 index 0000000..bcd2974 --- /dev/null +++ b/CTS_Solver.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/out/production/CTS_Solver/tech/loedige/Main.class b/out/production/CTS_Solver/tech/loedige/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..98cc06426e3bd50a8546e4caa7ada283ec70087a GIT binary patch literal 2073 zcmZuydvg<296g&RO&cPQAcZ27i#+U;-Mo_q!EBP%NGa9SDi+c0=9(KAdw zPoe$+jLh%>{7{bPZbBe!+nu}jaqjt@dw##W`S-tn-U3)hGlBr7!U#qY!nB67&+G$R zZ`qxO{%G%+bUY2ycioQb-P16&xU@5a84Y^E5~YkV$|6+~W>Tb5B4de6P7TXBku^m+ zBPt1z=TcGR(-A~)DvW3pAK|oy*@5S_^zxv+ui<=CzNmRUx6?@M9eT3Z>)D4I<`y^J z>liK~Nke29Dkq8wQ8Glz5OK~IMLZ+&B~i(XvNeO4hPUas z$fbo<5~+kJrbL1}l1d`g=aM2z-5HT9i%MKrJb+b-D^$@E*{m?LDwtVR{Zy8WB3@Kv zIWonCkr$bYdaR71(ry=&{g%Q%Ci@WC1agQTdz_l<$6xZ=7ljA30l1)Q+UvalO40lqRb|ScmTVdRe;xjC2IOj>H zskgea?lz?U&~~{oQkPEeaNjF!*EpaS_3tNmnH!3gn$8t{v%6*2>nx23R;-~3P0}Q(oPt84cCt|Ru8u9p52z7>?zI&awsUOyBb0&A9QXN z_oBFuFPJEG=`@&&)nSOfbOt@wJJhMDaAeBYTWmGD1T@F#sMn;%e;0`36?^2AI4HMeEIZ#SqYQhDLXeb4Q7`eA&h;l_l= zo88*LX^u)}j11%ZQ8M(gh1Jf1-E!-6@&njo4Y&PzAH#-(V_!eO?vAkIimA3*vSGK( zR@Zr6bAOW`V1LpeCUly1{kX`VH5il8MRe~$5DjB}ptMO?upik+vl%YOXSFa|d8 zkl1M~V-t_4DN589djalRz&GqoaVCmy*$bjZ>}jI6v4bD*Bc9+Xzq9=0jkNzx%rr48 zv8C5o*?fceP5uR(9PR()uDf#ELIc*}3A23~>Dxet}K7F&=Xd4y9bd8Pp-k`%d^%3g4#mCls&Y JSMCp>@jsmU={EoX literal 0 HcmV?d00001 diff --git a/out/production/CTS_Solver/util/Dump.class b/out/production/CTS_Solver/util/Dump.class new file mode 100644 index 0000000000000000000000000000000000000000..515d45c81db52a52275e54311faeda2261e5cb8c GIT binary patch literal 5431 zcma)Ad3+S*8GgP!vPTB8ENmbbY!EcrECj(KkccKxAd-L>4rA0ZNhZm{W_P(y%SY7cAg{#F0vr_$%0nIsFW{WZyNcIKP+d(Y>6 zzIXHThsRC;ScQKF;ey)-j|MM_6hb@nU3z^|PxaSt?A~GYmCVy-Rg&5 z!F5f}kDvmA&@j!1=^9E9I&E`@nN6hn6@pnKlhk{RresoKMNQk3dRwC5?3LQHm;4AT zs8wQamWBvQ=~dE5^_v5hSFJwGQK%d;6UqA4WYXx@lk1G(ONRzCmkswA88eYi`BAP= zy0N!6ni?AHHnP!lUo@5I?oJxH>L6yLQsS>th!k+KcB>ekry+`Jg+OkoJLg1KTGQHE zz}+Cu!2%x^YB(3?Da@D(x;14Q{YF;7pV6~9gOBv8fXUWc##E~?Z))oX%kMSm?4WK= zh81QJ>oml%NMZJ%zSC$)r+RdATf!XRUCz`~W=`R}f)>tBv-n-FVTpw4H`8{7!cbT$ zCYC9jTR>64_%(b?!*X1xP;92RWHLs!M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T$?ZDv;+AE^=_oSks4Hco1?Y`Yo()Lj3S?>n- za!JVaJ|f;w z^kD?~vF9+tiz1$V9z|85#aoUbH2E0u-nGRsQ4tTD*8WBAP-qmpw#A>qh%6jAb$!Hh z5W#r()0SfKsB^jJ0Alf?P$=T*9SB9oaf9WXqafnRS0KoXkK(3Le0B_Do!ma}}RYbnrWn16JWq0c%BtoFtF% z$U17>^%9*o#E#(>kew%}bGjw^7;$%m|5bWC51SSEk;UOugqP@puv!IvjGs`wV3Rx- zwCpZ&>^5>qddwfIkfNl-NIoo|v6S1K?4MNbca#U@TalybA!-svuPc85UU!4Qv|QlH z8tt7s#GJ!w=?)VabDHo zWkx7JbykENxhXFMVaGZR?xGJ66mB@l6DELH@T%kMe`rn$dabWf{2ap<+K*$u_;jb; zNwE`$urxx*hS^n_gD9TB_M-5YJkP<^>1G=(9>+Z$qd2&YopR*VYZD@8M;Bw2VAbGd z-n~Ljd6g&fYpBKRJotWwHGFO(`ZnX|R-|%9mlDl3is&X~U#A8avG`M~szH*i9qCM5 zP7QA``BL9GaG&B69MHX**AXbo|ud3tdax8;fKOs9mk=kF(T8EvIY$s wT+^BC5;`kSzpzaI62IbSIoE$p$=_SoKU&v!tn0h@E8hqC?r-=9{)Mvt0@fA@O#lD@ literal 0 HcmV?d00001 diff --git a/out/production/CTS_Solver/util/IllegalHexDumpException.class b/out/production/CTS_Solver/util/IllegalHexDumpException.class new file mode 100644 index 0000000000000000000000000000000000000000..f6d121818ab000fd654f040c3ebcd60c3d44a367 GIT binary patch literal 380 zcmaJ-%Sr=55UgI;U0tJz3wjEIo_v708wrRH6c#U$+$Za>j?B)6aYpi6o&*p106$9X z(TJj8ADXVBsP3-Ux0e}!Bjgz(ETo8ASVThDxfhS3r-i9{S6a(T=o4G{S{ipgE#<_i z#t@QYWt1BbHg=0|{m@xus{Y<6#S)?Gozh<(mvVaM>&Xv`__Vo|gm$5fy!Q22+8Z&} z%;ZH=3Oy251w1EXcc&f*Tg88-eFCv4|9cW48#dmS@hk%5{mso uDBPDB4VVplvVZUldg3WU#ytcGtg>hw6!umVC_**3a literal 0 HcmV?d00001 diff --git a/src/tech/loedige/Main.java b/src/tech/loedige/Main.java new file mode 100644 index 0000000..9fad4dd --- /dev/null +++ b/src/tech/loedige/Main.java @@ -0,0 +1,35 @@ +package tech.loedige; + +import util.Dump; + +import javax.crypto.*; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.NoSuchAlgorithmException; + +public class Main { + + public static void main(String[] args) throws NoSuchPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException { + // write your code here + byte[] key = Dump.hexString2byteArray("2F C6 0D 4C B3 44 6F 68 4C D8 7B 56 E2 93 4A 95"); + byte[] iv = Dump.hexString2byteArray("E7 80 29 0F 30 66 E8 A2 C0 40 19 0A 16 9C E9 DF"); + byte[] secret = Dump.hexString2byteArray("51 85 FC 42 A4 28 A3 E2 B3 83 7C D6 8D E1 F8 7F" + + "C1 A4 AF 77 B7 29 BA 77 47 DF 1A 85 82 A1 09 6E " + + "6E F6 A3 A1 5E 90 54 DB 33 71 00 00 00 00 00 00 " + + "36 B5 1D E8 68 A6 91 91 4D 8F 09 A0 9B CF E8 55"); + System.out.println(Dump.dump(secret)); + byte[] message = decryptCTS(key,iv,secret); + System.out.println(Dump.dump(message)); + } + + private static byte[] decryptCTS(byte[] key, byte[] iv, byte[] secret) throws InvalidAlgorithmParameterException, InvalidKeyException, NoSuchPaddingException, NoSuchAlgorithmException, BadPaddingException, IllegalBlockSizeException { + Cipher cipher = Cipher.getInstance("AES/CTS/NoPadding"); + SecretKey secretKey = new SecretKeySpec(key,"AES"); + IvParameterSpec IV = new IvParameterSpec(iv); + cipher.init(Cipher.DECRYPT_MODE,secretKey,IV); + return cipher.doFinal(secret); + } +} diff --git a/src/util/Dump.java b/src/util/Dump.java new file mode 100644 index 0000000..2aec87d --- /dev/null +++ b/src/util/Dump.java @@ -0,0 +1,215 @@ +/* + * Stefan Heiss + * TH Ostwestfalen-Lippe + * FB Elektrotechnik und Technische Informatik + * Quellcode zur Lehrveranstaltung Datensicherheit + */ +package util; + +import java.math.BigInteger; +import java.util.Formatter; + +public class Dump { + + public final static String NL + = System.getProperty("line.separator", "\r\n"); + + public static byte[] hexString2byteArray( + String hexString) { + // remove all whitespaces + hexString = hexString.replaceAll("\\s", ""); + hexString = hexString.replaceAll(":", ""); + + if ((hexString.length() & 0x01) != 0) { + throw new IllegalHexDumpException( + "Odd number of nibbles!"); + } + int byteArrayLength = hexString.length() >> 1; + byte[] ba = new byte[byteArrayLength]; + for (int i = 0; i < byteArrayLength; ++i) { + try { + ba[i] + = (byte) Integer.parseInt( + hexString.substring(2 * i, 2 * i + 2), 16); + } catch (NumberFormatException nfe) { + throw new IllegalHexDumpException( + "Invalid characters " + + hexString.substring(2 * i, 2 * i + 2) + + " at position " + 2 * i + + " (of streamlined string)!"); + } + } + return ba; + } + + // ------------------------------------------------------ + public static String dumpString(int i) { + String retString = Integer.toString(i, 16); + if ((retString.length() & 0x01) != 0) { + retString = "0" + retString; + } + + return retString.toUpperCase(); + } + + public static String dumpString(byte b) { + return dumpString(b & 0xff); + } + + public static String dumpString(byte[] data) { + return dumpString(data, 0, data.length); + } + + public static String dumpString( + byte[] data, int offset, int length) { + return dumpString(data, "", offset, length); + } + + public static String dumpString( + byte[] data, String interBytesString, + int offset, int length) { + if (offset < 0 || length < 0) { + throw new IllegalArgumentException( + "Values for offset and parameters must be " + + "non-negative!"); + } + if (data == null) { + if (offset > 0 || length > 0) { + throw new IllegalArgumentException( + "Specified range not available in data!"); + } + return ""; + } + if ((offset + length) > data.length) { + throw new IllegalArgumentException( + "Specified range not available in data!"); + } + + StringBuffer sb = new StringBuffer(length + * (2 + interBytesString.length())); + for (int i = offset; i < offset + length; ++i) { + if (i != 0) { + sb.append(interBytesString); + } + sb.append(dumpString(data[i])); + } + return new String(sb); + } + + // ------------------------------------------------------ + public static String dump(BigInteger b) { + byte[] data = b.toByteArray(); + int l = data.length; + if (l > 1 && data[0] == 0) { + System.arraycopy(data, 1, data, 0, --l); + } + return dump(data, l); + } + + public static String dump(byte[] data) { + return dump(data, data.length); + } + + public static String dump(byte[] data, int length) { + StringBuffer sb + = new StringBuffer(78 * ((length + 15) >> 4)); + char[] txt = new char[16]; + + int i = 0; + for (; i < length;) { + if ((i & 0x0f) == 0) { + sb.append(alignRight( + Integer.toHexString(i) + " ", 9, '0')); + } + + int temp = (0xff & data[i]); + sb.append(dumpString(temp)); + sb.append(" "); + + if (temp < 0x20 || temp > 0x7e) /// ??? + { + txt[i++ & 0x0f] = '.'; + } // if( temp == 0x0a || temp == 0x09 || temp == 0x0d ) /// ??? + // txt[i++ & 0x0f] = (char)0; + else { + txt[i++ & 0x0f] = (char) temp; + } + + if ((i & 0x0f) == 0) { + sb.append(" "); + sb.append(txt, 0, 16); + sb.append(NL); + } + } + + if (i == 0) // empty data + { + sb.append("000000 "); + } + + if ((i = (i & 0x0f)) != 0) { + sb.append(fillString(3 * (16 - i), ' ') + " "); + sb.append(txt, 0, i); + sb.append(NL); + } + + return new String(sb.toString().trim()); + } + + /** + * @return If str.length() < totalLength, a String of + * length totalLength is returned. (The original String + * extended by specified character from the left.) + */ + public static String alignRight( + String str, int totalLength, char fillChar) { + if (totalLength <= str.length()) { + return str; + } + return fillString(totalLength - str.length(), fillChar) + + str; + } + + /** + * @return If str.length() < totalLength, a String of + * length totalLength is returned. (The original String + * extended by space characters from the left.) + */ + public static String alignRight( + String str, int totalLength) { + return alignRight(str, totalLength, ' '); + } + + /** + * @return A String of repLength many repetitions of + * specified character. + */ + public static String fillString( + int spaceLength, char fillChar) { + if (spaceLength < 0) { + spaceLength = 0; + } + StringBuffer sb = new StringBuffer(spaceLength); + for (int i = 0; i < spaceLength; ++i) { + sb.append(fillChar); + } + return new String(sb); + } + + // ------------------------------------------------------ + public static String dumpIntArray(int[] array) { + int nosPerLine = 4; + StringBuffer sb = new StringBuffer(); + Formatter formatter = new Formatter(sb); + for (int i = 0; i < array.length; ++i) { + if (i != 0 && i % nosPerLine == 0) { + sb.append(NL); + } + formatter.format(" %08x", array[i]); + } + sb.append(NL); + return new String(sb); + } +} + + diff --git a/src/util/IllegalHexDumpException.java b/src/util/IllegalHexDumpException.java new file mode 100644 index 0000000..4e26cdf --- /dev/null +++ b/src/util/IllegalHexDumpException.java @@ -0,0 +1,15 @@ +/* + * Stefan Heiss + * TH Ostwestfalen-Lippe + * FB Elektrotechnik und Technische Informatik + * Quellcode zur Lehrveranstaltung Datensicherheit + */ +package util; + +public class IllegalHexDumpException + extends IllegalArgumentException { + + public IllegalHexDumpException(String s) { + super(s); + } +}