Einzelnen Beitrag anzeigen
Alt 07.01.08, 23:01   #33 (permalink)
satan92
 
Registriert seit: 03.11.07
satan92 Leistung: Facit NTK
Likes: 0
Standard

Hi, ich hab das ganze noma in c++ geschrieben, man kann die Datein und den Schluessel auch als argumente über die bash / cmd mit auf den weg geben weil ich im mom noch eine grafische "Oberfläche" dazu schreib und ich habe statt dem verschieben modulo genommen aber wenn man die ^ durch + / - ersätzt leufts aufs gleiche raus.
Einziges Problem ist das keine größeren datein gehen weil der long int der die datei größe "zählt" sonst platzt das muss ich noch umschreiben.
//auf win getestet sollte aber uebertragbar sein
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

void replace(string& text,const string& fnd,const string& rep) 
{ 
  size_t pos = text.find(fnd); 
  while(pos!=string::npos) 
  { 
    text.replace(pos,pos+fnd.length(),rep); 
    pos = text.find(fnd,pos); 
  } 
}

unsigned long int lof(ifstream &f){     //Length Of File
unsigned long int d; 
f.seekg(0,ios::end);    //Zeiger ans Ende der Datei setzen 
d=f.tellg();            //Position des Zeigers auslesen  
f.seekg(0,ios::beg);    //Zeiger zum Anfang der Datei setzen  
return(d);
}



void fencrypt(std::ifstream& srcfile,std::ofstream& dstfile,char *key,bool log, const char *datei)
{
//cout<<"void";
int keypos = 0, strpos = 0,i,f;
char buf, str[lof(srcfile)+1000000];
cout<<"while";
while(!srcfile.eof())
{
str[strpos] = srcfile.get();
strpos++;
//cout<<"sa";
}
cout<<strpos;
cout<<" bytes zu verschluesseln\n";
f=strpos;
str[strpos] = '\0'; strpos = 0;
srcfile.close();
//cout<<str[strpos+1];
i=0;
while(i<f)
{
//cout<<"while";
if(key[keypos] == '\0') keypos = 0;
buf = key[keypos];
if(log){std::cout << "Verschluessel  \"" << str[strpos] << "\" mit  \"" << buf <<"\": ";}
//+
str[strpos] ^= (int)buf;
if(log){std::cout << str[strpos] <<std::endl;}
dstfile.put(str[strpos]);
strpos++; keypos++;i++; 
}
}














void fcrypt(std::ifstream& srcfile,std::ofstream& dstfile,char *key,bool log, const char *datei)
{
//cout<<"void";
int keypos = 0, strpos = 0,i,f;
char buf, str[lof(srcfile)+1000000];
//cout<<"while";
while(!srcfile.eof())
{
str[strpos] = srcfile.get();
strpos++;
//cout<<"sa";
}
cout<<strpos;
f=strpos;
str[strpos] = '\0'; strpos = 0;
cout<<" bytes zu verschluesseln\n";
srcfile.close();
cout<<str[strpos+1];
i=0;
while(i<f)
{
//cout<<"while";
if(key[keypos] == '\0') keypos = 0;
buf = key[keypos];
if(log){std::cout << "Entschluessel  \"" << str[strpos] << "\" mit \"" << buf <<"\": ";}
//-
str[strpos] ^= (int)buf;
if(log){std::cout << str[strpos] <<std::endl;}
dstfile.put(str[strpos]);
strpos++; keypos++;i++; 
}
}











int a, b, c, d, e, falsch, u;
ifstream dat_ein;
ofstream dat_aus;
string zeile, zneu, key, dat;
//char *datei;
char datei[110], adatei[110];
char ki[10000];
string ss, sc, sh;

int main (int argc, char *argv[]){
	u=0;
	//cout<<argc;
	if(argc==4){
		u=1;
		strcpy (datei, argv[1]);
		strcpy (adatei, argv[2]);
		key=argv[3];
	}
	if(argc>1&&argc<4){
		cout<<"Der Funktionsaufruf lautet: [datei], [ausgabedatei], [schluessel]\n";
	}
	if(u==0){
	cout<<"Bls Datei Verschluesselung version 2.0\nc by Moritz Hpkt alle Rechte vorbehalten \n";
	}
	e=1;
	while(e==1){
	falsch=0;	
	if(u==0){
	cout<<"1: Verschluesseln \n2: Entschluesseln\n";
	cin>>a;
	cout<<"datei:\n";
	cin>>datei;
	cout<<"ausgabe Datei (ein und ausgabe Datei dürfen nicht indentisch sein) :\n";
	cin>>adatei;
	}
	if(strcmp(datei, adatei) == 0){
		falsch=1;
	}
	if(falsch==0){
	dat_ein.open(datei, ios::binary);
	dat_aus.open(adatei, ios::binary);
	if(u==0){
	cout<<"key: \n";
	cin>>key;
	}
	strcpy (ki, key.c_str());
	//cout<<"char";
	if(a==1){
		fencrypt(dat_ein,dat_aus,ki, false, datei);
	}
	else
	{
		fcrypt(dat_ein,dat_aus,ki, false, datei);
	}

cout<<"Vorgang erfolgreich ausgabe datei:\n";
cout<<adatei;
	}
	else
	{
		cout<<"Der Vorgang wurde abgebrochen, ein und ausgabe Datei stimmten ueber ein";
	}
if(u==0){
cout<<"\n1: Weitere Dateien ver/entschluesseln\n0: beenden\n";	
cin>>e;	
}
else
{
	e=0;
}
	}
return 0;
}

Geändert von satan92 (22.11.09 um 23:00 Uhr)
satan92 ist offline   Mit Zitat antworten
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61