008
31.03.2003, 15:11 Uhr
Tesla
|
Also so sieht das aus, warscheinlich werdet ihr euch jetzt amarsch lachen?
C++: |
#include <iostream.h> #include <math.h> #include <fstream.h> #include <stdlib.h> #include <string> #include <time.h> #define TRUE 1 #define FALSE 0 void ckey (); void verschlusseln (); void entschlusseln ();
int main () { int s; cout << " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n + Dies ist ein Programm das mit dem One-time-tape-Verfahren + \n + verschlüsseln soll. + \n ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"; cout << " 1. Create a Key \n 2. Verschlüsseln\n 3. Entschlüsseln\n 0. Exit \n"; cin >> s; switch (s) { case 0: { break; } case 1: { ckey (); break; } case 2: { verschlusseln (); break; } case 3: { entschlusseln (); break; } }
return 0; }
void ckey () { using namespace std; string str; char a; ofstream key ("key.txt", ofstream::binary); cout << "Länge des Schlüssels in MB angeben: "; int s; cin >> s; int size; size = s*1024*1024; char * buffer; buffer = new char [size]; static int first_time = TRUE; if (first_time) { first_time = FALSE; srand((unsigned int)time(NULL)); } if (key.is_open ()) { for (int i = 0; i < s*1024*1024; i++) { buffer[i] = (char) rand(); } key.write (buffer,size); key.close (); delete[] buffer; } } void verschlusseln () { char a,b; ifstream key ("key.txt"); ifstream data ("data.txt"); ofstream data2 ("data2.txt"); int size1, size2, c; key.seekg (0, ifstream::end); size1=key.tellg(); key.seekg(0); data.seekg (0, ifstream::end); size2=data.tellg(); data.seekg(0); char * buffer1; char * buffer2; char * buffer3; buffer1 = new char [size1]; buffer2 = new char [size2]; buffer3 = new char [size2]; if (! (key.is_open()) && (data.is_open())&& (data2.is_open())) { cout << "Fehler beim öffnen der Dateien"; exit (1); } if ((key.is_open()) && (data.is_open()) && (data2.is_open())) key.read (buffer1,size1); data.read (buffer2,size2); for (int i = 0; i < size2; i++) { a = buffer1[i]; b = buffer2[i]; c = (int)a+(int)b; buffer3[i] = (char)c; } /*while ((data.get(a)) && (key.get(b))) { c = (int)a+(int)b; data2 << c; }*/ data2.write (buffer3,size2); data2.close (); key.close (); data.close (); delete[] buffer1; delete[] buffer2; delete[] buffer3; } void entschlusseln () { char a,b; ifstream key ("key.txt"); ifstream data2 ("data2.txt"); ofstream data3 ("data3.txt"); int size1, size2, c; key.seekg (0, ifstream::end); size1=key.tellg(); key.seekg(0); data2.seekg (0, ifstream::end); size2=data2.tellg(); data2.seekg(0); char * buffer1; char * buffer2; char * buffer3; buffer1 = new char [size1]; buffer2 = new char [size2]; buffer3 = new char [size2]; if (! (key.is_open()) && (data2.is_open())&& (data3.is_open())) { cout << "Fehler beim öffnen der Dateien"; exit (1); } if ((key.is_open()) && (data2.is_open()) && (data3.is_open())) key.read (buffer1,size1); data2.read (buffer2,size2); for (int i = 0; i < size2; i++) { a = buffer1[i]; b = buffer2[i]; c = (int)a+(int)b; buffer3[i] = (char)c; } /*while ((data.get(a)) && (key.get(b))) { c = (int)a+(int)b; data2 << c; }*/ data3.write (buffer3,size2); data2.close (); key.close (); data3.close (); delete[] buffer1; delete[] buffer2; delete[] buffer3; }
|
data ist dabei der zuverschlüsselnde text, kex natürlich der schlüssel und data2 der verschlüsselte text und data3 die wieder entschlüsselte version. bringt das euch weiter? MFG Tesla --
C++: |
if(rpc_reg(RUSERSPROG, RUSERSVERS, RUSERSPROC_NUM, rusers, xdr_void, xdr_u_long, "visible") == -1) {fprintf(stderr, "Couldn'tRegister\n");
|
|