# Help in code to crack a symantic key for a TEA algorithm

Discussion in 'C' started by elsa87, Oct 10, 2008.

1. ### elsa87New Member

Joined:
Oct 10, 2008
Messages:
21
0
Trophy Points:
0
hi everyone..i need to crack a symmetric key by implementing a method called CrackSymmetricKey
I must use the TEA encryption algorithm below:
Code:
```union myMsgType{
unsigned long textConverted;
char text;
};

class TEA_Algorithm
{
public:
void CrackSymmetricKey(union myMsgType plaintext, union myMsgType ciphertext);
void Decrypt(unsigned long k[], unsigned long ciphertext[], unsigned long plaintext[]);
void Encrypt(unsigned long k[], unsigned long plaintext[], unsigned long ciphertext[]);
TEA_Algorithm() {};
virtual ~TEA_Algorithm() {};

};

```
As input, im given the following ciphertext and i need to find the secret key that has been used to obtain this ciphertext, and hence, deduce the original plaintext.
// myCiphertext.textConverted = 2022673309;
// myCiphertext.textConverted = 3810199360;

Code:
```#include "stdafx.h"
#include <iostream>
#include <string.h>
using namespace std;

#include "TEA_Algorithm.h"

void TEA_Algorithm::Encrypt(unsigned long k[], unsigned long plaintext[], unsigned long ciphertext[])
{
unsigned long y = plaintext, z = plaintext;
unsigned long delta = 0x9e3779b9, sum = 0; int n;
for (n= 0; n < 32; n++) {
sum += delta;
y += ((z << 4) + k) ^ (z+sum) ^ ((z >> 5) + k);
z += ((y << 4) + k) ^ (y+sum) ^ ((y >> 5) + k);
}
ciphertext = y;  ciphertext = z;

}

void TEA_Algorithm::Decrypt(unsigned long k[], unsigned long ciphertext[], unsigned long plaintext[])
{
unsigned long y = ciphertext, z = ciphertext;
unsigned long delta = 0x9e3779b9, sum = delta << 5;  int n;
for (n= 0; n < 32; n++) {
z -= ((y << 4) + k) ^ (y + sum) ^ ((y >> 5) + k);
y -= ((z << 4) + k) ^ (z + sum) ^ ((z >> 5) + k);
sum -= delta;
}
plaintext = y; plaintext = z;
}

void TEA_Algorithm::CrackSymmetricKey(union myMsgType plaintext, union myMsgType ciphertext)
{
/*
what should i write here if this is what's given:
plaintext:= security
ciphertext:
myCiphertext.textConverted = 2022673309;
myCiphertext.textConverted = 3810199360;