id
stringlengths
36
36
text
stringlengths
1
1.25M
88e70d31-5735-46b1-8f4d-26f4b98ac2ea
public static String convertArrayToString (int[] intArray) { String convertedString = ""; for (int anIntArray : intArray) { convertedString += anIntArray + ""; } return convertedString; }
afcde3e2-1778-4172-ad37-a80750ac8c06
public static int getNegativeX(int x) { while (x < 0) { // Convert to positive value. x = -x; // Subtract 11 and convert back to positive. x = (x - 11) * -1; } return x; }
1fc5dbfa-94b9-4e20-b3ab-586cae372888
public static int getPowerX(int x) { // Multiple x * x then take mod 11. x = (x * x) % 11; return x; }
f84dcae6-fb75-4f37-a23c-913fcc3e16ed
public static int sqrtX(int x) { // Check if square root is possible. while (Math.sqrt(x) % 1 != 0 && x < 100) { x += 11; } double ans = Math.sqrt(x) % 11; // Check if integer. if ((ans % 1) == 0) { x = (int)ans; } else { x = 0; } return x; }
0b09ae25-54e4-4761-b434-02d16530fc94
public static int getNegativePowerOld (int x) { // 1/5 = ? 1 = 5x int numerator = 1; int counter = 1; // Increment the numerator by 11 until its mod 11 = 0. // 1, 12, 23, 34, 45 while (numerator % x != 0) { numerator += 11; counter ++; } // Divide the new numerator by the counter to find x. // 45 = 5x = 9 x = numerator / counter; return x; }
38155f23-3979-4e6b-b343-46523a48ec82
public static int getNegativePower(int x) { int n = 11, t = 0, newt = 1, r = n, newr = x, q, temp; while(newr != 0) { q = r / newr; /* integer division */ temp = newt; /* remember newt */ newt = t - q * newt; t = temp; temp = newr; /* remember newr */ newr = r - q * newr; r = temp; } if(r > 1) return -1; /* not invertible */ if(t < 0) t = t + n; /* change to positive */ return t; }
f976d935-fd8e-433b-a878-5841a25f5455
public Cryptography() { ISBNValidatorButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //Execute when button is pressed System.out.println("You clicked the button"); } }); }
75d1af97-778f-471b-ae9e-61352152ddbf
@Override public void actionPerformed(ActionEvent e) { //Execute when button is pressed System.out.println("You clicked the button"); }
14238d97-66ac-426b-8a4c-132c37ffb875
public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); }
a606f7ca-5d7c-451c-9485-45cbbad01bc4
public void run() { createAndShowGUI(); }
3d5d1b8b-c9f2-4d2b-b9fa-b1d1a2e6093f
private static void createAndShowGUI() { JFrame rootPanel = new JFrame("JAVA"); rootPanel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton(" >> JavaProgrammingForums.com <<"); //Add action listener to button button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //Execute when button is pressed System.out.println("You clicked the button"); } }); rootPanel.getContentPane().add(button); rootPanel.pack(); rootPanel.setVisible(true); }
27fee817-ce89-46ab-bd16-743f0833dbc1
@Override public void actionPerformed(ActionEvent e) { //Execute when button is pressed System.out.println("You clicked the button"); }
8befb118-2038-4491-8214-ceabdbc72522
public static void main(String[] args) { int d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, s1, s2, s3, s4; // Get input values. String initialNumber = SharedMethods.getFixedLengthNumber(10); // Add number to int array int[] intArray = SharedMethods.addToArray(initialNumber); // Assign user input to variables d1 = intArray[0]; d2 = intArray[1]; d3 = intArray[2]; d4 = intArray[3]; d5 = intArray[4]; d6 = intArray[5]; d7 = intArray[6]; d8 = intArray[7]; d9 = intArray[8]; d10 = intArray[9]; // Get parity bits s1 = getFirstParityBit(d1, d2, d3, d4, d5, d6, d7, d8, d9, d10); s2 = getSecondParityBit(d1, d2, d3, d4, d5, d6, d7, d8, d9, d10); s3 = getThirdParityBit(d1, d2, d3, d4, d5, d6, d7, d8, d9, d10); s4 = getForthParityBit(d1, d2, d3, d4, d5, d6, d7, d8, d9, d10); // Add parity bits if valid and print result addParityBits(s1, s2, s3, s4, initialNumber); }
ecea5c88-fa35-4de9-b88c-076ff4679b9a
public static int getFirstParityBit(int d1, int d2, int d3, int d4, int d5, int d6, int d7, int d8, int d9, int d10) { int s1 = (d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8 + d9 + d10) % 11; return s1; }
86b4a694-a4d4-4a6f-9d38-fdeab03ffb83
public static int getSecondParityBit(int d1, int d2, int d3, int d4, int d5, int d6, int d7, int d8, int d9, int d10) { int s2 = (d1 + 2*d2 + 3*d3 + 4*d4 + 5*d5 + 6*d6 + 7*d7 + 8*d8 + 9*d9 + 10*d10) % 11; return s2; }
497a3fdf-dfda-41bf-b128-bd1ce700411f
public static int getThirdParityBit(int d1, int d2, int d3, int d4, int d5, int d6, int d7, int d8, int d9, int d10) { int s3 = (d1 + 4*d2 + 9*d3 + 5*d4 + 3*d5 + 3*d6 + 5*d7 + 9*d8 + 4*d9 + d10) % 11; return s3; }
b199a0a7-d839-4bae-876f-01c7a4ee0ce8
public static int getForthParityBit(int d1, int d2, int d3, int d4, int d5, int d6, int d7, int d8, int d9, int d10) { int s4 = (d1 + 8*d2 + 5*d3 + 9*d4 + 4*d5 + 7*d6 + 2*d7 + 6*d8 + 3*d9 + 10*d10) % 11; return s4; }
26d7a7f2-45ab-4412-a99d-69eb1b025b2e
public static void addParityBits(int s1, int s2, int s3, int s4, String initialNumber) { String finalValue = initialNumber + "" + s1 + "" + s2 + "" + s3 + "" +s4; System.out.println(finalValue); }
da5b2e87-1c5e-4cc3-b2c0-1d962f07e827
public static void main(String[] args) { // Get input values. int x = Integer.parseInt(SharedMethods.getVariableLengthNumber()); int y = Integer.parseInt(SharedMethods.getVariableLengthNumber()); // Calculate (x + y) mod 11 int addResult = calcAddMod(x, y); // Calculate (x * y) mod 11 int multiplyResult = calcMultiplyMod(x, y); // Calculate (x / y) mod 11 int divideResult = calcDivideMod(x, y); // Print results printResults(x, y, addResult, multiplyResult, divideResult); }
1ae6a4ce-59a1-40bb-adb7-41365f8179ef
private static int calcAddMod(int x, int y) { int addTemp = x + y; // Fixes negative numbers while ((addTemp) < 0) { addTemp += 11; } return addTemp % 11; }
f8ebd761-ee67-4b61-b848-ca2141d6274f
private static int calcMultiplyMod(int x, int y) { int multiplyTemp = x * y; // Fixes negative numbers while (multiplyTemp < 0) { multiplyTemp += 11; } return multiplyTemp % 11; }
2487a92e-7e49-4eea-910e-3798354bcf65
private static int calcDivideMod(int x, int y) { int divideTemp = x / y; // Fixes negative numbers while (divideTemp < 0) { divideTemp += 11; } return divideTemp % 11; }
0cf0e0c9-d184-4125-a543-5a60dfbde415
private static void printResults(int x, int y, int addResult, int multiplyResult, int divideResult) { System.out.println("(" + x + " + " + y + ") mod 11 = " + addResult); System.out.println("(" + x + " * " + y + ") mod 11 = " + multiplyResult); System.out.println("(" + x + " / " + y + ") mod 11 = " + divideResult); }
9ab0ba29-d014-4764-b971-ba3fb7b5113f
public static void main(String[] args) { // Generate 10 digit number from user input. String finalValue = getTenDigitEncodedValue(); // Print Result System.out.println(finalValue); }
08deb9a3-482a-4599-8748-11befb820dc5
public static String getTenDigitEncodedValue() { int d1, d2, d3, d4, d5, d6, d7, d8, d9, d10; // Get input values. String initialNumber = SharedMethods.getFixedLengthNumber(6); // Add number to int array int[] intArray = SharedMethods.addToArray(initialNumber); // Assign user input to variables d1 = intArray[0]; d2 = intArray[1]; d3 = intArray[2]; d4 = intArray[3]; d5 = intArray[4]; d6 = intArray[5]; // Get parity bits d7 = getFirstParityBit(d1, d2, d3, d4, d5, d6); d8 = getSecondParityBit(d1, d2, d3, d4, d5, d6); d9 = getThirdParityBit(d1, d2, d3, d4, d5, d6); d10 = getForthParityBit(d1, d2, d3, d4, d5, d6); // Add parity bits if valid and print result return addParityBits(d7, d8, d9, d10, initialNumber); }
11c4bc99-9faa-4f83-9504-dd46f2b1091b
public static int getFirstParityBit(int d1, int d2, int d3, int d4, int d5, int d6) { int d7 = (4 * d1 + 10 * d2 + 9 * d3 + 2 * d4 + d5 + 7 * d6) % 11; return d7; }
fbd87944-dbf6-4249-bca9-638e9bb6aec2
public static int getSecondParityBit(int d1, int d2, int d3, int d4, int d5, int d6) { int d8 = (7 * d1 + 8 * d2 + 7 * d3 + d4 + 9 * d5 + 6 * d6) % 11; return d8; }
bffce11c-0b72-4f68-8ceb-374de93fa096
public static int getThirdParityBit(int d1, int d2, int d3, int d4, int d5, int d6) { int d9 = (9 * d1 + d2 + 7 * d3 + 8 * d4 + 7 * d5 + 7 * d6) % 11; return d9; }
cc87e686-5167-4a79-af5a-5602d98c5184
public static int getForthParityBit(int d1, int d2, int d3, int d4, int d5, int d6) { int d10 = (d1 + 2 * d2 + 9 * d3 + 10 * d4 + 4 * d5 + d6) % 11; return d10; }
2e1555e4-251d-4b7a-921e-387fa92cd9c7
public static String addParityBits(int d7, int d8, int d9, int d10, String initialNumber) { String finalValue = ""; if (d7 >= 10 || d8 >= 10 || d9 >= 10 || d10 >= 10) { finalValue ="Unusable Number"; } else { finalValue = initialNumber + "" + d7 + "" + d8 + "" + d9 + "" + d10; } return finalValue; }
92cf383d-5145-42e7-b17d-90f4b7a47745
public static void main(String[] args) { // Initialise Variables int d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, s1, s2, s3, s4, p = 0, q = 0, r = 0, i=0, j=0, a=0, b=0; int error = 10; String decodedValue, encodedInput; int[] intArray; // Get input encodedInput = getInput(); // Add number to int array intArray = SharedMethods.addToArray(encodedInput); // Assign user input to variables d1 = intArray[0]; d2 = intArray[1]; d3 = intArray[2]; d4 = intArray[3]; d5 = intArray[4]; d6 = intArray[5]; d7 = intArray[6]; d8 = intArray[7]; d9 = intArray[8]; d10 = intArray[9]; // Get parity bits s1 = BCH_Generator.getFirstParityBit(d1, d2, d3, d4, d5, d6, d7, d8, d9, d10); s2 = BCH_Generator.getSecondParityBit(d1, d2, d3, d4, d5, d6, d7, d8, d9, d10); s3 = BCH_Generator.getThirdParityBit(d1, d2, d3, d4, d5, d6, d7, d8, d9, d10); s4 = BCH_Generator.getForthParityBit(d1, d2, d3, d4, d5, d6, d7, d8, d9, d10); // Check No Error if (s1 == 0 && s2 == 0 && s3 == 0 && s4 == 0) { error = 0; } // Check Single Error if (error != 0) { // Get P, Q & R p = getP(s1, s2, s3); q = getQ(s1, s2, s3, s4); r = getR(s2, s3, s4); // Check Single Error if (p == 0 && q == 0 && r == 0) { error = 1; } } // Check Double Error if (error != 0 && error != 1) { // Get Quadratic Equation Result int quadraticResult = getQuadraticResult(p, q, r); // Get i & j i = getI(p, q, quadraticResult); j = getJ(p, q, quadraticResult); // Get a & b b = getB(s1, s2, i, j); a = getA(s1, b); // Check Double or Larger Error if (i != 0 && j != 0 && quadraticResult != 0) { error = 2; } else { error = 3; } } //Output Result. outputResult(s1, s2, s3, s4, p, q, r, i, j, a, b, error, encodedInput, intArray); }
1531468a-9720-4aa0-a3fc-e4d2843fcd37
private static String getInput() { String encodedInput;// Get valid encoded 10 digit value. //encodedInput = getEncodedInput(); // Get invalid encoded 10 digit value. //encodedInput = SharedMethods.getFixedLengthNumber(10); // No Errors //encodedInput = "3745195876"; // Single Errors //encodedInput = "3945195876"; //encodedInput = "3645195876"; //encodedInput = "3745195877"; // Double Errors //encodedInput = "8883880744"; //encodedInput = "8899880747"; //encodedInput = "3715195076"; //encodedInput = "0743195876"; //encodedInput = "3745195840"; //encodedInput = "8745105876"; //encodedInput = "3745102876"; //encodedInput = "1145195876"; //encodedInput = "3745191976"; //encodedInput = "3745190872"; //encodedInput = "0745195877"; // Bigger Error encodedInput = "2745795878"; //encodedInput = "3742102896"; //encodedInput = "1115195876"; //encodedInput = "3121195876"; //encodedInput = "0888888074"; return encodedInput; }
46451a0e-ff90-44f1-8fb5-acab15ab693b
public static String getEncodedInput() { String encodedInput = "Unusable Number"; do { // Get 6 digit user input and encode it to a 10 digit String. encodedInput = Hamming_Generator.getTenDigitEncodedValue(); System.out.println("Encoded Value: " + encodedInput); } while (encodedInput.equals("Unusable Number")); return encodedInput; }
a1610ebc-a839-4d11-822c-53de6e9268c8
private static int getP(int s1, int s2, int s3) { int p = ((SharedMethods.getPowerX(s2)) - (s1 * s3)) % 11; while ( p < 0) {p += 11;} return p; }
482fcfc3-1fd6-402f-9931-6185b8caadd7
private static int getQ(int s1, int s2, int s3, int s4) { int q = ((s1 * s4) - (s2 * s3)) % 11; while ( q < 0) {q += 11;} return q; }
e6d6f5f0-76e3-4f6a-8d83-4b05c520afae
private static int getR(int s2, int s3, int s4) { int r = ((SharedMethods.getPowerX(s3)) - (s2 * s4)) % 11; while ( r < 0) {r += 11;} return r; }
4a689221-3d2f-49fb-910e-f3dcb4037ac7
public static int getI(int p, int q, int quadraticResult) { // Get i Numerator int iNumerator = -q + quadraticResult; iNumerator = SharedMethods.getNegativeX(iNumerator); // Get Denominator int denominator = getDenominator(p); // Get i int i = (iNumerator * denominator) % 11; return i; }
350b5b60-9738-41c2-8b9f-d9931620d3e1
public static int getJ(int p, int q, int quadraticResult) { // Get j Numerator int jNumerator = -q - quadraticResult; jNumerator = SharedMethods.getNegativeX(jNumerator); // Get Denominator int denominator = getDenominator(p); // Get j int j = (jNumerator * denominator) % 11; return j; }
48145a93-81c1-48d6-b87d-513de8f1eebb
private static int getDenominator(int p) { int denominator = (2 * p) % 11; denominator = SharedMethods.getNegativePower(denominator); return denominator; }
b922db20-2479-4dc8-87fd-ded4dd41cfbf
private static int getQuadraticResult(int p, int q, int r) { //(- Q ± √(Q2-4*P*R)) / 2*P // (Q ^ 2) - (4 * P * R) int quadraticResult = (q * q) - (4 * p * r); // quadraticResult mod 11 quadraticResult = quadraticResult % 11; quadraticResult = SharedMethods.getNegativeX(quadraticResult); // Square root result. quadraticResult = SharedMethods.sqrtX(quadraticResult); return quadraticResult; }
11209207-8128-4a26-98f5-f6ec338836fe
public static int getA(int s1, int b) { //a = s1 – b int a = (s1 - b); a = SharedMethods.getNegativeX(a); return a; }
99325f85-afaf-40e5-a870-0aba4f19d4af
public static int getB(int s1, int s2, int i, int j) { //b = (i*s1- s2) / (i - j) // Calculate Numerator int bNumerator = ((i*s1)- s2) % 11; bNumerator = SharedMethods.getNegativeX(bNumerator); // Calculate Denominator int bDenominator = (i - j); bDenominator = SharedMethods.getNegativeX(bDenominator); // Get b. int b = getPosition(bDenominator, bNumerator); return b; }
fa8bd457-b911-4fec-8e0e-4806a3fff289
private static int getPosition(int denominator, int numerator) { // s2/s1 =8/5 = 8*5^-1 =8*9 = 6 // Convert s1 to correct value (e.g. 5 -> 5^-1 -> 9). int newDenominator = SharedMethods.getNegativePower(denominator); // Multiple correct s1 & s2 values and mod 11. int position = (numerator * newDenominator) % 11; position = SharedMethods.getNegativeX(position); return position; }
62cb2731-937d-4188-9c90-aad9528621ee
public static int getCorrectBitValue (int[] intArray, int position, int magnitude) { // Incorrect bit - magnitude int tempArrayValue = intArray[position -1] - magnitude; // If result is less than 0 find matching positive value. tempArrayValue = SharedMethods.getNegativeX(tempArrayValue); // Mod result by 11. int correctBitValue = tempArrayValue % 11; return correctBitValue; }
5abd7317-3c5a-472b-a8f6-b0eff5b9ac3d
public static void outputNoError(String encodedInput) { String decodedValue = encodedInput; System.out.println("\nEncoded Value: " + encodedInput); System.out.println("Decoded Value: " + decodedValue); System.out.println("No Error"); }
1c58da54-a389-4fe3-b537-7133cbdebb51
public static void outputSingleError(String encodedInput, int s1, int s2, int s3, int s4, int[] intArray) { // Get position & magnitude. int position = getPosition(s1, s2); int magnitude = s1; // Special case if position is 0 then there is more than 2 errors. if (position < 1 || position > 10) { outputLargeError(encodedInput, s1, s2, s3, s4, 0, 0, 0); } else { // Get correct bit value intArray[position - 1] = getCorrectBitValue(intArray, position, s1); // Convert array to String String decodedValue = SharedMethods.convertArrayToString(intArray); // Print Result System.out.println("\nEncoded Value: " + encodedInput); System.out.println("Decoded Value: " + decodedValue); System.out.print("Single Error | "); System.out.print("Position [i]: " + position + " | "); System.out.print("Magnitude [a]: " + magnitude + " | "); System.out.print("Syn (" + s1 + ", " + s2 + ", " + s3 + ", " + s4 + ")"); } }
88cfda49-99b5-4d28-bbd5-8c66a5119dd1
public static void outputDoubleError(int s1, int s2, int s3, int s4, int p, int q, int r, String encodedInput, int[] intArray, int i, int j, int a, int b) { // Get position & magnitude. String decodedValue; int position1 = i, magnitude1 = a ,position2 = j ,magnitude2 = b; // Special case if position is 0 then there is more than 2 errors. if ((position1 < 1 || position1 > 10) || (position2 < 1 || position2 > 10)) { outputLargeError(encodedInput, s1, s2, s3, s4, 0, 0, 0); } else { // Get correct bit value intArray[position1 - 1] = getCorrectBitValue(intArray, i, a); intArray[position2 - 1] = getCorrectBitValue(intArray, j, b); // Convert array to String decodedValue = SharedMethods.convertArrayToString(intArray); // Print Result System.out.println("\nEncoded Value: " + encodedInput); System.out.println("Decoded Value: " + decodedValue); System.out.print("Double Error | "); System.out.print("Position [i]: " + position1 + " | "); System.out.print("Magnitude [a]: " + magnitude1 + " | "); System.out.print("Position [j]: " + position2 + " | "); System.out.print("Magnitude [b]: " + magnitude2 + " | "); System.out.print("Syn (" + s1 + ", " + s2 + ", " + s3 + ", " + s4 + ") | "); System.out.println("pqr (" + p + ", " + q + ", " + r + ")"); } }
f6717fe4-d726-4f50-aebc-906aba990dc9
public static void outputLargeError(String encodedInput, int s1, int s2, int s3, int s4, int p, int q, int r) { // Print Result System.out.println("\nEncoded Value: " + encodedInput); System.out.print("Large Error - No Square Root | "); System.out.print("Syn (" + s1 + ", " + s2 + ", " + s3 + ", " + s4 + ") | "); System.out.println("pqr (" + p + ", " + q + ", " + r + ")"); }
51ff67d9-1070-44ad-afe9-9bec7173f380
public static void outputResult(int s1, int s2, int s3, int s4, int p, int q, int r, int i, int j, int a, int b, int error, String encodedInput, int[] intArray) { switch (error) { case 0: outputNoError(encodedInput); break; case 1: outputSingleError(encodedInput, s1, s2, s3, s4, intArray); break; case 2: outputDoubleError(s1, s2, s3, s4, p, q, r, encodedInput, intArray, i, j, a, b); break; case 3: outputLargeError(encodedInput, s1, s2, s3, s4, p, q, r); default: System.out.println("Something has gone wrong!"); } }
61824080-94ae-4df0-9e51-4952118a8606
public static void main(String[] args) throws IOException { getSHA1(); }
fb3995a0-120b-4d68-a48e-8bdd3afcca5c
public static String getSHA1() throws IOException { BufferedReader userInput = new BufferedReader (new InputStreamReader(System.in)); //System.out.println("Enter string:"); String rawString = userInput.readLine(); try { System.out.println("SHA1 hash of string: " + SHA1.SHA1(rawString) + "\n"); return SHA1.SHA1((rawString)); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return ""; }
e6a8a19c-765a-4474-8a5a-014866eebfa1
private static String convertToHex(byte[] data) { StringBuffer buf = new StringBuffer(); for (int i = 0; i < data.length; i++) { int halfbyte = (data[i] >>> 4) & 0x0F; int two_halfs = 0; do { if ((0 <= halfbyte) && (halfbyte <= 9)) buf.append((char) ('0' + halfbyte)); else buf.append((char) ('a' + (halfbyte - 10))); halfbyte = data[i] & 0x0F; } while(two_halfs++ < 1); } return buf.toString(); }
da255079-1a05-4beb-a566-fbc683fc4b52
public static String SHA1(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException { MessageDigest md = MessageDigest.getInstance("SHA-1"); //Test // System.out.println("md: " + md); byte[] sha1hash = new byte[40]; //Test //System.out.println("sha1hash" + sha1hash); md.update(text.getBytes("iso-8859-1"), 0, text.length()); //Test //System.out.println("md: " + md); sha1hash = md.digest(); //Test //System.out.println("sha1hash" + sha1hash); return convertToHex(sha1hash); }
c6762700-6819-4735-8e08-db88a7d59e4f
public static void main(String[] args) throws IOException, NoSuchAlgorithmException { // Get Hash value System.out.print("Enter a plain text password to be hashed using SHA1: "); String encodedHash = SHA1.getSHA1(); System.out.println("Brute Forcing...\n"); // Loop from 1 to the maximum number of characters for (int wordLength = 1; wordLength <= MAX_WORD_LENGTH; wordLength++) { // Generate all combinations for the word length and check for a match. if (generate(wordLength, charSet, encodedHash)) { System.out.print("\n\nMatch found!! The decrypted string is : " + answer); break; } else { System.out.println("\nPassword has more than " + wordLength + " characters"); } } }
a83da005-df13-4246-b588-10b830155faa
private static boolean generate(int wordLength, char[] charSet, String encodedHash) throws UnsupportedEncodingException, NoSuchAlgorithmException { // Total number of combinations for the word length. final long MAX_WORDS = (long) Math.pow(CHARSETLENGTH, wordLength); // For the number of possible combinations. for (long currentCombo = 0; currentCombo < MAX_WORDS; currentCombo++) { // Calculate int values of characters in each position [0, 0, 1, 1]. int[] indices = getCharSetPositions(CHARSETLENGTH, currentCombo, wordLength); // Create array 'word' the length of the word length currently being tested. char[] word = new char[wordLength]; // For each char position, assign the corresponding character in 'charSet' to the int value in 'indices'. for (int charPosition = 0; charPosition < wordLength; charPosition++) { word[charPosition] = charSet[indices[charPosition]]; } // Convert character array to String to test. String possiblePassword = new String(word); // Print out current word - TEST LINE System.out.print(possiblePassword + ", "); // Compare encrypted possible solution with the encoded hash. if (compare(SHA1.SHA1(possiblePassword), encodedHash)) { answer = possiblePassword; return true; } } return false; }
738e0557-5941-420c-8db0-8a0a9a2d4989
private static int[] getCharSetPositions(int charSetLength, long currentCombo, int wordLength) { // Set array for length of word int[] indices = new int[wordLength]; // For the number of characters in the word for (int i = wordLength - 1; i >= 0; i--) { // If left most character is unchanged (a) set to 0. if (currentCombo == 0) { indices[i] = 0; } else { /* Finds the char position value using mod as counter goes above charSet length. /* e.g. 36 = 1, 37 = 2 etc.*/ int position = (int) (currentCombo % charSetLength); indices[i] = position; /* CurrentCombo counts the number of changes made to the selected position. * As there are 35 characters, for a 2 char word the currentCombo calculates as follows: * [0, 34], [0, 35], [1, 36], [1, 37]. * Dividing the right side results in the correct value for the left. */ currentCombo /= charSetLength; } } return indices; }
cf987340-f8da-42ca-bef1-9996b32311e8
public static boolean compare(String possiblePassword, String encodedHash) { if (encodedHash.contains(possiblePassword)) return true; else { return false; } }
201057c8-c2a7-45d4-bc45-4b563f622b93
public static void main(String[] args) throws IOException, NoSuchAlgorithmException { // Get Hash value System.out.print("Enter a plain text password containing exactly two integers to be hashed using SHA1: "); String encodedHash = SHA1.getSHA1(); System.out.println("Brute Forcing...\n"); // Loop from 1 to the maximum number of characters for (int wordLength = 1; wordLength <= MAX_WORD_LENGTH; wordLength++) { // Generate all combinations for the word length and check for a match. if (generate(wordLength, charSet, encodedHash)) { System.out.print("\n\nMatch found!! The decrypted string is : " + answer); break; } else { System.out.println("\nPassword has more than " + wordLength + " characters"); } } }
33405b89-aa26-4c82-8f57-39456398bfcf
private static boolean generate(int wordLength, char[] charSet, String encodedHash) throws UnsupportedEncodingException, NoSuchAlgorithmException { // Total number of combinations for the word length. final long MAX_WORDS = (long) Math.pow(CHARSETLENGTH, wordLength); // For the number of possible combinations. for (long currentCombo = 0; currentCombo < MAX_WORDS; currentCombo++) { // Calculate int values of characters in each position. e.g. [0, 0, 1, 1]. int[] indices = getCharSetPositions(CHARSETLENGTH, currentCombo, wordLength); // Check to see if there are exactly 2 numbers. int counter = 0; for(int i=0; i < indices.length; i++){ if (indices[i] > 25) { counter ++; } } // If there are two numbers run as normal. if (counter == 2) { // Create array 'word' the length of the word length currently being tested. char[] word = new char[wordLength]; // For each char position, assign the corresponding character in 'charSet' to the int value in 'indices'. for (int charPosition = 0; charPosition < wordLength; charPosition++) { word[charPosition] = charSet[indices[charPosition]]; } // Convert character array to String to test. String possiblePassword = new String(word); // Print out current word System.out.print(possiblePassword + ", "); // Compare encrypted possible solution with the encoded hash. if (compare(SHA1.SHA1(possiblePassword), encodedHash)) { answer = possiblePassword; return true; } } } return false; }
4aa52d3b-c2eb-46a2-a1c0-938c9378e9b4
private static int[] getCharSetPositions(int charSetLength, long currentCombo, int wordLength) { // Set array for length of word int[] indices = new int[wordLength]; // For the number of characters in the word for (int i = wordLength - 1; i >= 0; i--) { // If left most character is unchanged (a) set to 0. if (currentCombo == 0) { indices[i] = 0; } else { /* Finds the char position value using mod as counter goes above charSet length. /* e.g. 36 = 1, 37 = 2 etc.*/ int position = (int) (currentCombo % charSetLength); indices[i] = position; /* CurrentCombo counts the number of changes made to the selected position. * As there are 35 characters, for a 2 char word the currentCombo calculates as follows: * [0, 34], [0, 35], [1, 36], [1, 37]. * Dividing the right side results in the correct value for the left. */ currentCombo /= charSetLength; } } return indices; }
c08fedd8-b613-4080-9f93-80cb8800e592
public static boolean compare(String possiblePassword, String encodedHash) { if (encodedHash.contains(possiblePassword)) return true; else { return false; } }
6a579873-409a-45f1-9a5d-8cfc6bece909
public static void main(String[] args) { // Get ISBN number String isbn = getISBN(); // Remove Symbols String isbnFormat = removeSymbols(isbn); // Add ISBN to int array int[] intArray = SharedMethods.addToArray(isbnFormat); // Multiply ISBN values int ISBNTotal = multiplyISBNValues(intArray); // Mod ISBN Total int ISBNMod = modISBNTotal(ISBNTotal); // Get last Element Value int isbnLastElement = intArray[isbnFormat.length() - 1]; // Check if ISBN is valid checkIfISBNIsValid(ISBNMod, isbnLastElement); }
5b99cc39-9dee-4f3c-864f-0674a10fa666
private static String getISBN() { Scanner scan = new Scanner(System.in); boolean validInput = false; String isbn = ""; // Ensure input is valid. while (!validInput) { System.out.print("Enter an ISBN (e.g. 0-19-853287-3): "); isbn = scan.nextLine(); // If characters are correct if (isbn.matches("([0-9]+-?)+")) { // If length is correct if (isbn.length() == 10 || isbn.length() == 13) { validInput = true; } else { System.out.print("Invalid input. Ensure the value contains 10 numbers.\n"); } } else { System.out.print("Invalid input. Contains incorrect characters\n"); } } return isbn; }
d57b0147-cc87-477c-b403-0a9b20ac5339
private static String removeSymbols(String isbn) { return isbn.replaceAll("-", ""); }
7e686833-2167-4ad6-8aaa-7c8a61162059
private static int multiplyISBNValues(int[] intArray) { int ISBNTotal = 0; // Multiply all but last value using formula and total them for(int i = 0; i < intArray.length -1; i++) { intArray[i] = intArray[i] * (i + 1); ISBNTotal += intArray[i]; } return ISBNTotal; }
8993dcab-6b07-489f-b9ab-4c7f4f15de9a
private static int modISBNTotal(int ISBNTotal) { return ISBNTotal % 11; }
85400722-22e0-4cc4-a565-e8f6d525349f
private static void checkIfISBNIsValid(int ISBNMod, int isbnLastElement) { if (ISBNMod == isbnLastElement) { System.out.println("------------------"); System.out.println("The ISBN is valid."); System.out.println("------------------"); } else { System.out.println("----------------------"); System.out.println("The ISBN is not valid."); System.out.println("----------------------"); } }
05544fc5-39d9-40ee-8474-be0ff68ffe5f
public static void main(String[] args) { System.out.println("---- Credit Card Validator ----"); // Get Credit Card Number number String cardNumber = SharedMethods.getFixedLengthNumber(16); // Add Credit Card number to int array int[] intArray = SharedMethods.addToArray(cardNumber); // Multiply alternate values multiplyAlternateValues(intArray); // Total values int creditCardTotal = totalValues(intArray); // Mod Credit Card Total int creditCardMod = modCreditCardTotal(creditCardTotal); // Check if ISBN is valid checkIfValid(creditCardMod); }
9c73c7e8-0695-4648-8904-574c55ad617e
private static void multiplyAlternateValues(int[] intArray) { // For every other item in the array for(int i = 0; i < intArray.length; i+=2) { // Double the value intArray[i] *= 2; // Fix values over 10 if (intArray[i] > 9) { intArray[i] -= 9; } } }
8c9f1681-88c0-44e2-b9cd-bc8fed628d6f
private static int totalValues(int[] intArray) { int total = 0; for (int anIntArray : intArray) { total += anIntArray; } return total; }
442919fa-2173-437e-8502-5e790faba150
private static int modCreditCardTotal(int creditCardTotal) { return creditCardTotal % 10; }
28af5176-1f7d-4be0-b0ec-6152ef23e6a4
private static void checkIfValid(int creditCardMod) { if (creditCardMod == 0) { System.out.println("--------------------------------"); System.out.println("The Credit Card number is valid."); System.out.println("--------------------------------"); } else { System.out.println("------------------------------------"); System.out.println("The Credit Card number is not valid."); System.out.println("------------------------------------"); } }
1b90dc00-87d1-4142-97c7-328bc6cc8cbb
public static void main(String[] args) throws UnsupportedEncodingException, NoSuchAlgorithmException { int[] test = convertToRadix(26, 27, 4); System.out.print(Arrays.toString(test)); }
f1c3a468-a093-44d2-ac6a-bef18e58feca
private static int[] convertToRadix(int numOfPosChars, long currentCombo, int wordLength) { int[] indices = new int[wordLength]; for (int i = wordLength - 1; i >= 0; i--) { System.out.print(Arrays.toString(indices)); if (currentCombo > 0) { int rest = (int) (currentCombo % numOfPosChars); currentCombo /= numOfPosChars; indices[i] = rest; } else { indices[i] = 0; } } return indices; }
2b31975c-7ece-4dfe-872d-9e3949cce93a
public static void main(String... args) { System.out.println("Hello Talls! From Pwiggles' laptop!!"); Shape r1020 = new Rectangle(10, 20); Rectangle r3030 = new Rectangle(30, 30); EquilateralTriangle t3 = new EquilateralTriangle(3.14); ArrayList<Shape> shapesList = new ArrayList<Shape>(); shapesList.add(r1020); shapesList.add(r3030); shapesList.add(t3); double sumArea = 0; for (int i = 0; i < shapesList.size(); i++) { sumArea = sumArea + shapesList.get(i).getArea(); } ArrayList<Double> eq = new ArrayList<Double>(); eq.add(7.); eq.add(2.); eq.add(3.); eq.add(5.0); Integral fts = new Integral(); System.out.println(fts.getIntegral(eq, 0, 10, 100000)); /* System.out.println(shapesList.get(0).getArea()); System.out.println(shapesList.size()); System.out.println(sumArea); System.out.println(t3); System.out.println(t3); System.out.println(r1020); System.out.println(r3030); System.out.println(shapesList); */ }
83fc248d-9c82-490a-946d-ae4b80e63c0c
public double getIntegral(ArrayList<Double> eqCoeff, double xinitial, double xfinal, double numOfRect) { double recWidth = (xfinal - xinitial) / numOfRect; double sumYValues = 0; for (int i = 0; i < numOfRect; i++) { double yvalue = calcYValue(eqCoeff, xinitial + i * recWidth); sumYValues = sumYValues + yvalue; } return sumYValues * recWidth; }
b3bc6609-f41f-4809-ab68-5e77667066ca
public double calcYValue(ArrayList<Double> eqCoeff, double xvalue) { double yvalue = 0; for (int i = 0; i < eqCoeff.size(); i++) { double iCoeff = eqCoeff.get(i); yvalue = yvalue + iCoeff * Math.pow(xvalue, i); } return yvalue; }
04456fa3-3719-48f7-9d53-12bae9724e6e
public Rectangle(double length, double width) { this.length = length; this.width = width; }
3bf1fdbf-0302-4dea-8454-932b71f0d941
@Override public int getNumSides() { return 4; }
9d014657-7e3e-4d52-8e8f-833acef69e5c
public boolean isSquare() { return length == width; }
3923dd89-efc6-4e14-89bc-382b9e2362af
@Override public double getArea() { return length * width; }
dd59e6a7-407e-4baa-beee-c4c786a5e7a5
@Override public double getPerimeter() { return 2 * length + 2 * width; }
d3ebb6eb-6853-4375-b109-b2595b41f181
@Override public String toString() { if (isSquare()) { return "<Square side: " + length + ">"; } else { return "<Rectangle length: " + length + ", width: " + width + ">"; } }
e7991090-060c-410d-9fd4-72844fedbfa2
public EquilateralTriangle(double side) { this.side = side; }
f655ef1e-acea-42eb-bc2f-311117af20d8
@Override public int getNumSides() { return 3; }
a1f2e6dc-b4e5-4e78-a13f-1f303c346519
@Override public double getArea() { return Math.sqrt(3) * Math.pow(side, 2) / 4; }
2c8e30d9-fbbe-4f41-855e-abeda75d2621
@Override public double getPerimeter() { return 3 * side; }
a12f3969-c24e-4b36-964d-5fbbdde62fdf
@Override public String toString() { return "<Equilateral Triangle: " + side + ">"; }
324ab6f3-73eb-4183-bf48-f4a45c2ee184
public abstract int getNumSides();
4f01d47a-832a-43f9-a08a-80624285eaa8
@Override public String toString() { return "<Polygon: " + this.getNumSides() + ">"; }
aa2986a8-facf-4193-bfc5-00c3eec61bba
public abstract double getArea();
37338307-b050-47b2-9ad0-7dbda8a2d892
public abstract double getPerimeter();
c9a0549e-cca2-4d14-98be-4697aee06066
@Override public String toString() { return "<Shape>"; }
8acaf91d-1ee4-4259-9f1e-bcda4d24290d
public Queen(int x, int y, boolean isWhite) { super(x, y, isWhite); BufferedImage img; try { img = ImageIO.read(getClass().getResource("/enikon.png")); Image scaledImg = img.getScaledInstance(30, 30, java.awt.Image.SCALE_SMOOTH ); super.setIcon(new ImageIcon(scaledImg)); } catch (IOException e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
57bb1e72-6c85-40bc-93de-5c7aa1ba719a
@Override public HashSet<Square> getMoves() { return moves; }
3bfff184-5184-4ae3-a5c9-23cd63d12ebf
@Override public HashSet<Square> calcMoves(ChessBoard board) { moves = new HashSet<Square>(); for(int i = 1; checkMove(board.getSquare(x+i, y)); i++) {} for(int i = 1; checkMove(board.getSquare(x-i, y)); i++) {} for(int i = 1; checkMove(board.getSquare(x, y+i)); i++) {} for(int i = 1; checkMove(board.getSquare(x, y-i)); i++) {} for(int i = 1; checkMove(board.getSquare(x+i, y+i)); i++) {} for(int i = 1; checkMove(board.getSquare(x+i, y-i)); i++) {} for(int i = 1; checkMove(board.getSquare(x-i, y+i)); i++) {} for(int i = 1; checkMove(board.getSquare(x-i, y-i)); i++) {} return moves; }
9c31b1d1-1589-46e2-a9f9-09300312cecf
public Pawn(int x, int y, boolean isWhite) { super(x, y, isWhite); if (isWhite) { movement = -1; } else { movement = 1; } }
c69b2bd8-15c6-48ab-b74e-364df72b17f4
@Override public HashSet<Square> calcMoves(ChessBoard board) { moves.clear(); checkMove(board.getSquare(x, y + movement)); checkAttackMove(board.getSquare(x - 1, y + movement)); checkAttackMove(board.getSquare(x + 1, y + movement)); return moves; }
4bb0a183-47d8-43ae-88f9-cd064e72a993
@Override public HashSet<Square> getMoves() { return moves; }
63416563-ccf0-49f9-b3c6-de9358b5c57b
@Override protected boolean checkMove(Square square) { if (square.isBlocked()) { return false; } moves.add(square); return true; }