elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
26 Mayo 2012, 10:00  


Tema destacado: Nueva página de elhacker.net en Google+ Google+

+  Foro de elhacker.net
|-+  Seguridad Informática
| |-+  Seguridad
| | |-+  Criptografía (Moderador: APOKLIPTICO)
| | | |-+  Crypter sencillo de texto plano.
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Crypter sencillo de texto plano.  (Leído 1,378 veces)
IWKY

Desconectado Desconectado

Mensajes: 269



Ver Perfil
Crypter sencillo de texto plano.
« en: 8 Abril 2009, 20:01 »

Hola buenas, he programado un pequeño crypter de texto plano, bueno mas que crypter podríamos llamarlo barajador de texto plano xDD, la verdad no se estará bien publicado aquí o tendrá que estar en la parte de programación (si esta mal muevanlo), bueno les pongo el código para que lo vean y lo puedan probar si quieren, seguramente habrá muchos errores, así que todas las criticas serán bienvenidas.
De momento en esta primera versión solo admite los caracteres ASCII del 32 al 127.

jcrypt.h
Código
#ifndef JCRYPT_H_
#define JCRYPT_H_
 
#include <string>
using namespace std;
 
class jcrypt{
private:
char *ordenado;
char *desordenado;
int salto;
void IntToString(int, string &);
void cambiasalto(int);
public:
jcrypt(int =-1);
jcrypt(const jcrypt &);
jcrypt operator=(const jcrypt &);
~jcrypt();
string cifra(string &);
string descifra(string &);
};
#endif
 

jcrypt.cpp
Código
#include <iostream>
#include <time.h>
#include <cmath>
 
#include "jcrypt.h"
 
using namespace std;
 
const int ini = 32;
const int fin = 127;
const int N = 95;
 
jcrypt::jcrypt(int s){
ordenado = new char[N];
desordenado = new char[N];
for(int i=ini; i<fin; i++){
ordenado[i-ini] = i;
}
salto = s;
if(s==-1){
time_t semilla = time(NULL) + getpid();
srand(semilla);
salto = rand() % N;
}
 
for(int i=0; i<N; i++){
desordenado[i]=ordenado[(i+salto)%N];
}
}
 
jcrypt::jcrypt(const jcrypt &j){
ordenado = new char[N];
desordenado = new char[N];
 
for(int i=0; i<N; i++){
ordenado[i] = j.ordenado[i];
}
for(int i=0; i<N; i++){
desordenado[i] = j.desordenado[i];
}
}
 
jcrypt jcrypt::operator=(const jcrypt &j){
if(this != &j){
delete ordenado;
delete desordenado;
 
for(int i=0; i<N; i++){
ordenado[i] = j.ordenado[i];
desordenado[i] = j.desordenado[i];
}
}
return *this;
}
 
jcrypt::~jcrypt(){
delete ordenado;
delete desordenado;
}
 
string jcrypt::cifra(string & cad){
string nuevo;
int len = cad.length();
 
if(salto < 10) nuevo = "0";
 
IntToString(salto, nuevo);
 
for(int i=0; i<len; i++){
nuevo += desordenado[cad[i] - ini];
}
 
return nuevo;
}
 
string jcrypt::descifra(string &cad){
char s[2] = {cad[0], cad[1]}; //Salto
int pos, ss, len = cad.length();
string nuevo="";
ss = atoi(s);//Salto
 
if(salto != ss){
cambiasalto(ss);
}
 
for(int i=2; i<len; i++){
for(int j=0; j<N; j++){
if(cad[i] == desordenado[j]){
nuevo += j+32;
}
}
}
return nuevo;
}
 
void jcrypt::cambiasalto(int s){
for(int i=0; i<N; i++){
desordenado[i] = ordenado[(i+s) % N];
}
}
 
void jcrypt::IntToString(int i, string & s)
{
  // s = "";
   if (i == 0)
   {
       s = "0";
       return;
   }
   if (i < 0)
   {
       s += '-';
       i = -i;
   }
   int count = log10(i);
   while (count >= 0)
   {
       s += ('0' + i/pow(10.0, count));
       i -= static_cast<int>(i/pow(10.0,count)) * static_cast<int>(pow(10.0,count));
       count--;
   }
}
 

También un main por si no les apetece programar.
Código
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
 
#include "jcrypt.h"
 
using namespace std;
 
int main(int argc, char *argv[]){
fstream in;
fstream out;
string texto = "";
char aux;
string ttexto;
 
if(argc != 4){
cerr<<"ERROR: Pase de paramentros."<<endl;
cerr<<"enjcrypt E|D fich_in fich_out"<<endl;
cerr<<"E ->Eencriptar"<<endl;
cerr<<"D -> descifrar"<<endl;
exit(-1);
}
 
in.open(argv[2], ios::in);
out.open(argv[3], ios::out | ios::trunc);
 
 
if(!out || !in){
cerr<<"ERROR: No se han podido abrir los ficheros de E/S"<<endl;
exit(-1);
}
 
in.get(aux);
while(!in.eof()){
texto += aux;
in.get(aux);
}
in.close();
 
if(strcmp(argv[1],"E") == 0){
jcrypt var;
ttexto = var.cifra(texto);
}
else{
jcrypt var;
ttexto = var.descifra(texto);
}
 
for(int i=0; i<ttexto.length();i++){
out.put(ttexto[i]);
}
 
out.close();
 
return 0;
}
 



En línea

Por internet libre http://red-sostenible.net/
El mejor momento de Dragon Ball Z --> Aqui
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines