Package info.riemannhypothesis.crypto.tools

Examples of info.riemannhypothesis.crypto.tools.ByteSequence


public class Week4 {

  public static void main(String[] args) {
    // TODO Auto-generated method stub
    ByteSequence iv = ByteSequence.fromHexString("20814804c1767293b99f1d9cab3bc3e7");
    byte[] zeros = new byte[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    ByteSequence m1 = new ByteSequence("Pay Bob 100$").append(zeros);
    ByteSequence m2 = new ByteSequence("Pay Bob 500$").append(zeros);
    System.out.println("Result IV: " + iv.xor(m1).xor(m2).toHexString());
  }
View Full Code Here


        BigInteger plain = c.modPow(d, N1);
        String hex = plain.toString(16);
        String unpadded = hex.substring(hex.indexOf("00"));
        // System.out.println(plain);
        // System.out.println(plain.toString(16));
        ByteSequence sol = ByteSequence.fromHexString(unpadded);
        System.out.println(sol.toString());
    }
View Full Code Here

  public static void main(String[] args) throws IOException {

    String cipher = "f20bdba6ff29eed7b046d1df9fb7000058b1ffb4210a580f748b4ac714c001bd4a61044426fb515dad3f21f18aa577c0bdf302936266926ff37dbf7035d5eeb4";
    final byte blockLength = 16;
    ByteSequence bytes = ByteSequence.fromHexString(cipher);
    ByteSequence plain = ByteSequence.EMPTY_SEQUENCE;
    BlockSequence blocks = new BlockSequence(blockLength, bytes);

    for (int i = 1; i < blocks.length(); i++) {
      ByteSequence iv = blocks.blockAt(i - 1);
      ByteSequence block = blocks.blockAt(i);
      boolean lastBlock = (i == blocks.length() - 1);
      try {
        ByteSequence plainBlock = decryptBlock(iv, block);
        if (lastBlock) {
          byte paddingLength = plainBlock
              .byteAt(plainBlock.length() - 1);
          if (paddingLength < 1 || paddingLength > blockLength) {
            throw new Exception("Incorrect padding");
          }
          for (int pos = 1; pos < paddingLength; pos++) {
            if (plainBlock.byteAt(plainBlock.length() - 1 - pos) != paddingLength) {
              throw new Exception("Incorrect padding");
            }
          }
          plainBlock = plainBlock.range(0, plainBlock.length()
              - paddingLength);
        }
        System.out.println("The decryption of block " + i + " is: "
            + plainBlock.toString());
        plain = plain.append(plainBlock);
      } catch (Exception e) {
        System.out.print("There was an error: " + e.getMessage());
        e.printStackTrace();
      }
View Full Code Here

    return response;
  }

  public static ByteSequence decryptBlock(ByteSequence iv, ByteSequence cipher)
      throws CloneNotSupportedException, IOException {
    ByteSequence plain = new ByteSequence(new byte[cipher.length()]);
    boolean wrongGuess = false;
    byte avoidGuess = 0;
    for (int pos = cipher.length() - 1, pad = 1; pos >= 0; pos--, pad++) {
      ByteSequence attack = iv.append(cipher);
      boolean foundGuess = false;
      for (int guess = 0; guess < 256; guess++) {
        if (wrongGuess && guess == avoidGuess) {
          System.out.println("Skipped; pos: " + pos + "; pad: " + pad
              + "; guess: " + guess);
          continue;
        }
        byte subs = (byte) (iv.byteAt(pos) ^ guess ^ pad);
        attack.setByteAt(pos, subs);
        for (int i = 1; i < pad; i++) {
          subs = (byte) (iv.byteAt(pos + i) ^ plain.byteAt(pos + i) ^ pad);
          attack.setByteAt(pos + i, subs);
        }
        URL url = new URL(baseURL + attack.toHexString());
        int response = getResponseCode(url);
        System.out.println("pos: " + pos + "; pad: " + pad
            + "; guess: " + guess + "; attack: "
            + attack.toHexString() + "; reponse: " + response);
        if (response == 404) {
          System.out.println("Character at position " + pos + ": "
              + guess);
          plain.setByteAt(pos, (byte) guess);
          wrongGuess = false;
View Full Code Here

TOP

Related Classes of info.riemannhypothesis.crypto.tools.ByteSequence

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.