
import ast
import sys

def parse(line):
    return ast.literal_eval(line)

def main():
    if len(sys.argv) != 3:
        print("usage: ./find_ids.py [forward differentials file] [backward differentials file]", file=sys.stderr)
        sys.exit(1)

    forward_diffs = []
    with open(sys.argv[1]) as f:
        for i, forward_rounds, xss in map(parse, f):
            forward_diffs.append((i, forward_rounds, [set(xs) for xs in xss])

    backward_diffs = []
    with open(sys.argv[2]) as g:
        for i, backward_rounds, yss in map(parse, g):
            backward_diffs.append((i, backward_rounds, [set(ys) for ys in yss])

    # truncate first round of backward differential
    # by comparing last round of forward differential and second last
    # round of backward differential
    ids = []
    for i, forward_rounds, xss in forward_diffs:
        for j, backward_rounds, yss in backward_diffs:
            if xss[-1].isdisjoint(yss[-2]):
                backward_rounds -= 1
                print((i, forward_rounds, backward_rounds, j))

if __name__ == "__main__":
    main()


import ast
import sys

def parse(line):
    i, rounds, xss = ast.literal_eval(line)
    yss = [set(xs) for xs in xss]
    return (i, rounds, yss)

def main():
    if len(sys.argv) != 3:
        print("usage: ./find_ids.py [forward differentials file] [backward differentials file]", file=sys.stderr)
        sys.exit(1)

    ids = []
    with open(sys.argv[1]) as f:
        for i, forward_rounds, xss in map(parse, f): 
            if forward_rounds < 2:
                continue

            with open(sys.argv[2]) as g:
                for j, backward_rounds, yss in map(parse, g):
                    if backward_rounds < 2:
                        continue

                    # truncate first round of backward differential
                    # by comparing last round of forward differential and second last
                    # round of backward differential
                    if xss[-1].isdisjoint(yss[-2]):
                        backward_rounds -= 1
                        print((i, forward_rounds, backward_rounds, j))

if __name__ == "__main__":
    main()

Revert "Trade memory for time."
Revert "Trade memory for time."

This reverts commit f4c13756eef0dc6b7231e37d5f5d9029dea1fb62.

  
  import ast
  import sys
  
  def parse(line):
-     return ast.literal_eval(line)
+     i, rounds, xss = ast.literal_eval(line)
+     yss = [set(xs) for xs in xss]
+     return (i, rounds, yss)
  
  def main():
      if len(sys.argv) != 3:
          print("usage: ./find_ids.py [forward differentials file] [backward differentials file]", file=sys.stderr)
          sys.exit(1)
  
-     forward_diffs = []
+     ids = []
      with open(sys.argv[1]) as f:
-         for i, forward_rounds, xss in map(parse, f):
+         for i, forward_rounds, xss in map(parse, f): 
-             forward_diffs.append((i, forward_rounds, [set(xs) for xs in xss])
+             if forward_rounds < 2:
+                 continue
  
-     backward_diffs = []
-     with open(sys.argv[2]) as g:
+             with open(sys.argv[2]) as g:
-         for i, backward_rounds, yss in map(parse, g):
+                 for j, backward_rounds, yss in map(parse, g):
-             backward_diffs.append((i, backward_rounds, [set(ys) for ys in yss])
+                     if backward_rounds < 2:
+                         continue
  
-     # truncate first round of backward differential
+                     # truncate first round of backward differential
-     # by comparing last round of forward differential and second last
+                     # by comparing last round of forward differential and second last
-     # round of backward differential
+                     # round of backward differential
-     ids = []
-     for i, forward_rounds, xss in forward_diffs:
-         for j, backward_rounds, yss in backward_diffs:
-             if xss[-1].isdisjoint(yss[-2]):
+                     if xss[-1].isdisjoint(yss[-2]):
-                 backward_rounds -= 1
+                         backward_rounds -= 1
-                 print((i, forward_rounds, backward_rounds, j))
+                         print((i, forward_rounds, backward_rounds, j))
  
  if __name__ == "__main__":
      main()
  
Revert "Trade memory for time."
## Code Before:

import ast
import sys

def parse(line):
    return ast.literal_eval(line)

def main():
    if len(sys.argv) != 3:
        print("usage: ./find_ids.py [forward differentials file] [backward differentials file]", file=sys.stderr)
        sys.exit(1)

    forward_diffs = []
    with open(sys.argv[1]) as f:
        for i, forward_rounds, xss in map(parse, f):
            forward_diffs.append((i, forward_rounds, [set(xs) for xs in xss])

    backward_diffs = []
    with open(sys.argv[2]) as g:
        for i, backward_rounds, yss in map(parse, g):
            backward_diffs.append((i, backward_rounds, [set(ys) for ys in yss])

    # truncate first round of backward differential
    # by comparing last round of forward differential and second last
    # round of backward differential
    ids = []
    for i, forward_rounds, xss in forward_diffs:
        for j, backward_rounds, yss in backward_diffs:
            if xss[-1].isdisjoint(yss[-2]):
                backward_rounds -= 1
                print((i, forward_rounds, backward_rounds, j))

if __name__ == "__main__":
    main()

## Instruction:
Revert "Trade memory for time."
## Code After:

import ast
import sys

def parse(line):
    i, rounds, xss = ast.literal_eval(line)
    yss = [set(xs) for xs in xss]
    return (i, rounds, yss)

def main():
    if len(sys.argv) != 3:
        print("usage: ./find_ids.py [forward differentials file] [backward differentials file]", file=sys.stderr)
        sys.exit(1)

    ids = []
    with open(sys.argv[1]) as f:
        for i, forward_rounds, xss in map(parse, f): 
            if forward_rounds < 2:
                continue

            with open(sys.argv[2]) as g:
                for j, backward_rounds, yss in map(parse, g):
                    if backward_rounds < 2:
                        continue

                    # truncate first round of backward differential
                    # by comparing last round of forward differential and second last
                    # round of backward differential
                    if xss[-1].isdisjoint(yss[-2]):
                        backward_rounds -= 1
                        print((i, forward_rounds, backward_rounds, j))

if __name__ == "__main__":
    main()
