answersLogoWhite

0


Best Answer

/*

* 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

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C program to implement transposition cipher using key?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

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

Just fart!


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


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.


Can you make a sentence using the verb implement?

He decided to implement his plan.


1 What are the main advantages from using high-level language constructs?

Easy to test program Easier to implement programming solution Reduce the repeating code Easy to change and modify program Increase the productivity


How to do a password using vhdl?

A VHDL program can be written to provide a password in the following ways.Using FPGA:Your program can be dumped into a FPGA. This works as per the program written. As the code is burned into it, the user can not see the code. Now, within your program you can have a conditional statement which serves as your password. For example,if (c=ramarav) then...................................................................Using CPLD:It also works in the similar manner.Using a GUI:We can implement a graphical user interface, but the easier way is to take the help of MATLAB tool. We can implement our VHDL code in MATLAB tool and it serves the purpose.


Implement a full adder using 2 41 mux?

implement it. enough said.