Ok så jeg sad herr forleden og skulle forklare en ven epå nettet hvad et transpositions cipher er, det udviklede sig til dette program.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char *argv[])
{
char plaintext1[255];
char plaintext2[255];
char ciphertext[255];
int caesarkey = 0;
int stringlength = 0;
int i = 0;
cout<<"Next we are going to try a flip cipher, this is a little more complicated, so bear with me."<<endl;
cout<<endl<<"First off, enter a new plaintext: ";
cin.getline(plaintext2, 255, '\\n');
while(plaintext2[i] != '\\0'){i++;stringlength++;}
char flipcipher[stringlength+1];
int permuter[stringlength];
cout<<"Now we know that our ciphertext is "<<stringlength<<" Characters long. We are now going to move the characters around a little, for that we need to enter a key for them."<<endl;
cout<<"Please enter the numbers 0 - "<<stringlength-1<<" In a random order! Don't repeat yourself!"<<endl;
i = 0;
while(i < stringlength){
int n = 0;
int u = 0;
cout<<"Enter number: ";
cin>>n;
if(n>stringlength){
cout<<"Number too high! Try again!";
cin>>n;
i--;}
permuter[i] = n;
i++;}
i = 0;
cout<<"Ok now we have a permutor, let put it to use!"<<endl;
while(plaintext2[i] != '\\0'){
flipcipher[i] = plaintext2[permuter[i]];
i++;}
flipcipher[i+1] = '\\0';
i = 0;
cout<<"Ok now we have flipped the plaintext, let's look at it: "<<endl;
while(flipcipher[i] !='\\0'){
cout<<flipcipher[i];
i++;}
cout<<endl<<"OK! Now let us see if we can decode the text as well!"<<endl<<endl;
i = 0;
while(flipcipher[i] !='\\0'){
plaintext1[permuter[i]] = flipcipher[i];
i++;}
cout<<"If what comes next is your real text then we've won!"<<endl;
i = 0 ;
while(plaintext1[i] !='\\0'){
cout<<plaintext1[i];
i++;}
cout<<endl;
return 0;
}
Jeg er ikke ligefrem nogen haj til c++ så det er ikke så kønt, men det virker.
Problemet med det er at jeg mangler en eller anden smart måde at lave en permuter (eller key, eller nøgle forhåbenligt ved I hvad jeg mener). Som i kan se er den metode jeg bruger nu ikke lige frem strømlignet, så har i nogle idér? Både til hvordan jeg generer en nøgle og til programmet generelt.
Kunne rigtigt godt tænke mig en (relativ) simpel måde at generere en bare lidt random key.