/pba_singapore_multi_pad

Multi Pad attack example for assignment

Primary LanguageRust

Final results: Final Decrypted Messages With the correct key, the final decrypted messages are:

  1. Decrypted message 0: The Times 03/Jan/2009 Chancellor on brink of second bailout for banks.
  2. Decrypted message 1: Governments are good at cutting off the heads of a centrally controlled networks like Napster, but pure P2P networks like Gnutella and Tor seem to be holding their own.
  3. Decrypted message 2: Bitcoin is great as a form of digital money, but its scripting language is too weak for any kind of serious advanced applications to be built on top.
  4. Decrypted message 3: In order to have a decentralized database, you need to have security. In order to have security, you need to have incentives.
  5. Decrypted message 4: As society becomes more and more complex, cheating will in many ways become progressively easier and easier to do and harder to police or even understand.
  6. Decrypted message 5: I began to realize new possibilities opening up between the fields of ICT and game theory, and the inevitable social change to which this would lead.
  7. Decrypted message 6: Cryptocurrencies allowed non-custodial exchange, without users having to sign up or create accounts.
  8. Decrypted message 7: Not your keys, Not your coins.
  9. Decrypted message 8: Bitcoin: A purely peer-to-peer version of electronic cash would allow online payments to be sent directly from one party to another without going through a financial institution.

Explanation below


XOR Cipher Decryption

This project demonstrates the process of decrypting multiple ciphertexts that were XOR-encrypted with the same key. The key is partially known, and we aim to extract as much of the key as possible and use it to decrypt the messages.

Steps

Step 1: Convert Hex Strings to Byte Vectors

First, we convert the given hex-encoded ciphertexts to byte vectors.

let ciphertexts: Vec<Vec<u8>> = ciphertext_hex.iter().map(|&hex| hex_to_bytes(hex)).collect();
let min_len = ciphertexts.iter().map(|c| c.len()).min().expect("No ciphertexts provided");

Step 2: Initialize Key and Potential Keys

We initialize a key vector and a potential keys matrix. The potential_keys matrix will store potential keys for each byte position.

let mut key = vec![0u8; min_len];
let mut potential_keys = vec![vec![0; 256]; min_len];

Step 3: XOR Ciphertexts in Pairs

We XOR each pair of ciphertexts and record potential keys for each position where the XOR result is an ASCII alphabetic character.

for i in 0..ciphertexts.len() {
    for j in i + 1..ciphertexts.len() {
        let xored = xor_buffers(&ciphertexts[i][..min_len], &ciphertexts[j][..min_len]);
        for k in 0..xored.len() {
            if xored[k].is_ascii_alphabetic() {
                potential_keys[k][ciphertexts[i][k] as usize ^ b' ' as usize] += 1;
                potential_keys[k][ciphertexts[j][k] as usize ^ b' ' as usize] += 1;
            }
        }
    }
}

### Step 4: Decrypt approximately the Messages

```rust
for (i, ciphertext) in ciphertexts.iter().enumerate() {
    let decrypted_message: Vec<u8> = xor_buffers(&ciphertext[..min_len], &key);
    let decrypted_text = bytes_to_string(&decrypted_message);
    println!("Decrypted message {}: {}", i, decrypted_text);
}

Initial Results

Using the above steps, we obtained the following decrypted messages:

  1. Decrypted message 0: .he ...es 03 Fan/2009 Chacceal
  2. Decrypted message 1: .ove...ents n~e good at cxttdn
  3. Decrypted message 2: .itc... is g}iat as a for ok`
  4. Decrypted message 3: .n o...r to gmve a decent�aldz
  5. Decrypted message 4: .s s...ety bjoomes more acd o`
  6. Decrypted message 5: . be... to rjmlize new po~sioi
  7. Decrypted message 6: .ryp...urrenlees allowed con c
  8. Decrypted message 7: .ot ...r key| Not your cbin~.
  9. Decrypted message 8: .itc...: A pz~ely peer-to pehr

Step 5: Hypothesis Testing

We hypothesized that the beginning of the key is "Bitcoin: A purely peer-to-peer ". Using this known part of the key, we decrypted as much of the messages as possible.

Partial Decryption with Known Key Part

Using the known part of the key, we decrypted the ciphertexts as follows:

let key = "Bitcoin: A purely peer-to-peer ";
let key_bytes = key.as_bytes();

for (index, ciphertext) in ciphertexts.iter().enumerate() {
    let mut decrypted_message = Vec::new();
    for (i, &byte) in ciphertext.iter().take(key_bytes.len()).enumerate() {
        let key_byte = key_bytes[i % key_bytes.len()];
        decrypted_message.push(byte ^ key_byte);
    }
    if let Ok(decrypted_str) = str::from_utf8(&decrypted_message) {
        println!("Decrypted message {}: {}", index, decrypted_str);
    } else {
        println!("Decrypted message {} contains non-UTF-8 characters", index);
    }
}

Results with Known Key Part

Using the partial key "Bitcoin: A purely peer-to-peer ", we obtained the following decrypted messages:

  1. Decrypted message 0: The Times 03/Jan/2009 Chancello
  2. Decrypted message 1: Governments are good at cutting
  3. Decrypted message 2: Bitcoin is great as a form of d
  4. Decrypted message 3: In order to have a decentralize
  5. Decrypted message 4: As society becomes more and mor
  6. Decrypted message 5: I began to realize new possibil
  7. Decrypted message 6: Cryptocurrencies allowed non-cu
  8. Decrypted message 7: Not your keys, Not your coins.
  9. Decrypted message 8: Bitcoin: A purely peer-to-peer

These partial decryption validate our hypothesis about the key and provide more context to the messages.

Step 6: Extending the Key

After the space "Bitcoin: A purely peer-to-peer ", we tried all letters of the alphabet until reaching the letter 'V', which made sense. This extended the key to "Bitcoin: A purely peer-to-peer V".

Results with Extended Key Part

Using the extended key part, we obtained the following decrypted messages:

  1. Decrypted message 0: The Times 03/Jan/2009 Chancellor
  2. Decrypted message 1: Governments are good at cutting
  3. Decrypted message 2: Bitcoin is great as a form of di
  4. Decrypted message 3: In order to have a decentralized
  5. Decrypted message 4: As society becomes more and more
  6. Decrypted message 5: I began to realize new possibili
  7. Decrypted message 6: Cryptocurrencies allowed non-cus
  8. Decrypted message 7: Not your keys, Not your coins.
  9. Decrypted message 8: Bitcoin: A purely peer-to-peer v

Step 7: Extending the Key again

We then tried the word "version" to further extend the key, resulting in the following decrypted messages:

Results with Extended Key Part

Using the extended key part, we obtained the following decrypted messages:

  1. Decrypted message 0: The Times 03/Jan/2009 Chancellor on bri
  2. Decrypted message 1: Governments are good at cutting off the
  3. Decrypted message 2: Bitcoin is great as a form of digital m
  4. Decrypted message 3: In order to have a decentralized databa
  5. Decrypted message 4: As society becomes more and more comple
  6. Decrypted message 5: I began to realize new possibilities op
  7. Decrypted message 6: Cryptocurrencies allowed non-custodial
  8. Decrypted message 7: Not your keys, Not your coins.
  9. Decrypted message 8: Bitcoin: A purely peer-to-peer version

Final Realization

After further analysis and googling, we realized that the key is the abstract of the Bitcoin whitepaper:

"Bitcoin: A purely peer-to-peer version of electronic cash would allow online payments to be sent directly from one party to another without going through a financial institution."

Using this full key, we were able to decrypt the entire messages accurately.

Final Decrypted Messages With the correct key, the final decrypted messages are:

  1. Decrypted message 0: The Times 03/Jan/2009 Chancellor on brink of second bailout for banks.
  2. Decrypted message 1: Governments are good at cutting off the heads of a centrally controlled networks like Napster, but pure P2P networks like Gnutella and Tor seem to be holding their own.
  3. Decrypted message 2: Bitcoin is great as a form of digital money, but its scripting language is too weak for any kind of serious advanced applications to be built on top.
  4. Decrypted message 3: In order to have a decentralized database, you need to have security. In order to have security, you need to have incentives.
  5. Decrypted message 4: As society becomes more and more complex, cheating will in many ways become progressively easier and easier to do and harder to police or even understand.
  6. Decrypted message 5: I began to realize new possibilities opening up between the fields of ICT and game theory, and the inevitable social change to which this would lead.
  7. Decrypted message 6: Cryptocurrencies allowed non-custodial exchange, without users having to sign up or create accounts.
  8. Decrypted message 7: Not your keys, Not your coins.
  9. Decrypted message 8: Bitcoin: A purely peer-to-peer version of electronic cash would allow online payments to be sent directly from one party to another without going through a financial institution.

This README provides a detailed explanation of the steps taken to decrypt the XOR-encrypted messages, the initial decrypted results, the hypothesis testing, and the partial decryption using the known part of the key.