1
$\begingroup$

So I went ahead an wrote this little program. What it does is it takes a password for a seed and generates a (pseudo-random) bit-pattern using rule 30 from cellular automata. It then XORs our input file with the same-length pattern. In theory this should be secure, given I would start padding the plaintext and only use a password once?

import sys

def rule30(a, b, c):
    return (a ^ (b | c)) & 1

def next_generation(current_gen):
    padded_gen = [0] + current_gen + [0]
    new_gen = [0] * len(padded_gen)
    for i in range(1, len(padded_gen) - 1):
        new_gen[i] = rule30(padded_gen[i-1], padded_gen[i], padded_gen[i+1])
    return new_gen

def file_to_binary(filename):
    with open(filename, "rb") as file:
        content = file.read()
    binary_content = [int(b) for byte in content for b in format(byte, '08b')]
    return binary_content

def xor_binary_lists(list1, list2):
    return [a ^ b for a, b in zip(list1, list2)]

def binary_to_file(binary_list, filename):
    byte_list = [int(''.join(str(b) for b in binary_list[i:i+8]), 2) for i in range(0, len(binary_list), 8)]
    with open(filename, "wb") as file:
        file.write(bytes(byte_list))

def string_to_binary(seed_string):
    binary_str = ''.join(format(ord(c), '08b') for c in seed_string)
    return [int(b) for b in binary_str]

def rule30_xor(input_filename, output_filename, password):
    input_binary = file_to_binary(input_filename)
    input_length = len(input_binary)
    seed = string_to_binary(password)
    generation = seed

    while len(generation) < input_length:
        generation = next_generation(generation)

    xor_result = xor_binary_lists(input_binary, generation)
    binary_to_file(xor_result, output_filename)

if __name__ == "__main__":
    if len(sys.argv) != 4:
        print("Usage: python rule30.py input_file output_file password")
        sys.exit(1)

    input_filename = sys.argv[1]
    output_filename = sys.argv[2]
    password = sys.argv[3]
    rule30_xor(input_filename, output_filename, password)

Given the following output, can either the password or input file be recovered?

$ hexdump -x output.txt 
0000000    411c    1c99    b25d    9bbc    e751    c32e    8c28    0162
0000010    8bcc    b8eb    ce8a    d2f8    fec7 

What else am I missing from a security standpoint?

$\endgroup$
1
  • 1
    $\begingroup$ Post from community meta $\endgroup$
    – DannyNiu
    Mar 28 at 1:01

2 Answers 2

2
$\begingroup$

There have been people considering CA for cryptanalysis. The problem is that CA leads to an unbounded state and this uses unbounded memory. Thus some dubious claims of "breaking" cryptosystems which appear outside the mainstream crypto venues are largely ignored.

For your specific question you need to demonstrate exactly why anyone should be interested in yet another untested idea for a cipher. What advantage if any does CA bring? In the absence of this as well as a decent attempt at cryptanalyssis by yourself which demonstrates some level of security, you probably won't receive many responses.

$\endgroup$
2
$\begingroup$

Knowing a single plaintext/ciphertext pair $(p,c)$ at least as large as the password is enough to decipher any ciphertext $c'$ at least as large as $c$ encrypted with the same password.

Just compute $k=p\oplus c$, then while that's smaller than $c'$ expand $k$ per $k\gets\operatorname{next\_generation}(k)$. The desired plaintext $p'$ then is $c'\oplus k$.


The cost of the system as it stands is proportional to the square of the plaintext length, making it unusable for typical workloads.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.