answersLogoWhite

0

/*

* Transposition cipher cracker

*

* Algorithm used to find keys:

*

* n = keylength

* t = textlength

* a = t / n

* b = t % n

* d = accumulated rest terms

* k = wanted plain text position

* loc(k) = a * perm(k % n) + d(perm(k % n)) + k/n

*

* By Ben Ruijl, 2009

*

* compile: g++ -O2 col.cpp

*/

#include <iostream>

#include <cstring>

#define MAXKEY 20

const char* buffer = "irtyhockeibtdaamoelatcnsronhoniirttcacdeiunsihaioarnndgpruphahirgtoarnmclspstwe";

int buflength;

const char* crib = "computer";

int criblength;

void print(int* perm, int n)

{

int a = buflength / n;

int b = buflength % n;

//invert perm

int invperm[MAXKEY];

for (int i = 0; i < n; i++)

invperm[perm[i]] = i;

int d[MAXKEY] = {0};

for (int i = 1; i < n; i++)

{

d[i] = d[i -1];

if (invperm[i - 1] < b)

d[i]++;

}

std::cout << "Found: ";

for (int i = 0; i < buflength; i++)

std::cout << buffer[a * perm[i % n] + d[perm[i % n]] + i / n];

std::cout << std::endl;

}

bool checkperm(int* perm, int n)

{

int cribpos = 0;

int a = buflength / n;

int b = buflength % n;

//invert perm

int invperm[MAXKEY];

for (int i = 0; i < n; i++)

invperm[perm[i]] = i;

int d[MAXKEY] = {0};

for (int i = 1; i < n; i++)

{

d[i] = d[i -1];

if (invperm[i - 1] < b)

d[i]++;

}

for (int i = 0; i < buflength; i++)

{

if (buffer[a * perm[i % n] + d[perm[i % n]] + i / n] n - 1)

checkperm(v, n);

else

{

for (int i = start; i < n; i++)

{

int tmp = v[i];

v[i] = v[start];

v[start] = tmp;

permute(v, start + 1, n);

v[start] = v[i];

v[i] = tmp;

}

}

}

int main(int argv, char** argc)

{

int perm[MAXKEY];

for (int i = 0; i < MAXKEY; i++)

perm[i] = i;

buflength = strlen(buffer);

criblength = strlen(crib);

int curkey = 2; // start key

while (curkey < MAXKEY)

{

std::cout << "Testing key " << curkey << std::endl;

permute(perm, 0, curkey); // permutate keys

curkey++;

}

return 0;

}

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

How do you write a program a bout rotor cipher using C?

Just fart!


How will a cryptographer write the word EXPLETIVE?

A cryptographer would write the word &quot;EXPLETIVE&quot; by using a specific encryption method, such as a substitution cipher or a transposition cipher. In a substitution cipher, each letter in the word would be replaced with a different letter or symbol according to a predetermined key. In a transposition cipher, the letters in the word would be rearranged according to a specific algorithm. The resulting encrypted form of &quot;EXPLETIVE&quot; would be a scrambled or substituted version of the original word, making it difficult for unauthorized individuals to decipher without the key.


Write A program to implement insertion using AVL trees?

yes


What is a sentence using the word cipher?

The cipher made the intent of the message difficult to understand.


Write a program to implement a line using slope intercept formula?

lund lelo mooh mein


How do you run graphics program in C?

pro c language to implement linear search using pointers


How do you solve a cryptanalysis?

To solve a cryptanalysis problem, first, identify the type of cipher used (such as substitution, transposition, or more complex algorithms). Next, analyze the frequency of letters or patterns in the ciphertext to uncover potential keys or plaintext. Testing hypotheses about the key or using known plaintext attacks can further aid in breaking the cipher. Finally, iteratively refine your approach based on the results until the original message is revealed.


C program to implement tower of hanoi using array implementation of stack abstract datatype?

stack abstract datatype


How do you enhance a Vigenere cipher like making it harder to crack?

Using a keyword as long as the message will make a vigenere cipher unbreakable.


How do you implement a program to display the Indian flag with colors using c graphics?

ANSI/ISO C does not and never has done graphics.


Two different names for the cipher 0?

The cipher &quot;0&quot; is commonly known as the &quot;null cipher&quot; and the &quot;zero cipher.&quot; A null cipher encodes a message by hiding it within a larger body of text, often using specific letters or words to reveal the intended message, while the zero cipher is a more general term that can refer to any encoding that represents information with no visible changes in a certain context.


Can you make a sentence using the verb implement?

He decided to implement his plan.