Skip to content
Snippets Groups Projects
Commit e80f2733 authored by Marcela Ribeiro de Oliveira's avatar Marcela Ribeiro de Oliveira
Browse files

programa para criar o texto cifrado

parent ed646bef
No related branches found
No related tags found
No related merge requests found
......@@ -3,3 +3,4 @@
*.swo
playunfair
*.out
cypher
......@@ -5,18 +5,23 @@ INCL = -I ./include
DEPS = include/*
OBJ = playfair.o playunfair.o
OBJ = playfair.o
EXEC = playunfair
EXEC = playunfair cypher
$(EXEC): $(OBJ)
$(CC) $(CFLAGS) -o $@ $^
all: $(EXEC)
playunfair: $(OBJ)
$(CC) $(CFLAGS) -o $@ $^ $@.o
cypher: $(OBJ)
$(CC) $(CFLAGS) -o $@ $^ $@.o
%.o: %.cpp $(DEPS)
$(CC) $(CFLAGS) -c -o $@ $< $(INCL)
all: $(EXEC)
clean:
rm -f $(OBJ) playunfair
rm -f $(OBJ) $(EXEC)
#include "include/playunfair.h"
#include <fstream>
int main(int argc, char *argv[]){
if(argc!=3){
std::cout << "Uso: ./playunfair <file-in> <key>" << std::endl;
return 0;
}
std::fstream input, keyF;
char *inputName, *keyName;
std::string aux="", key, crip;
std::ostringstream text, keys;
inputName = argv[1];
keyName = argv[2];
input.open(inputName, std::ifstream::in);
if(!input.good()){
std::cout << "Nao foi possivel abrir o arquivo de entrada" << std::endl;
return 0;
}
while(std::getline(input, aux))
text << aux;
//TODO: tirar caracteres especiais
crip = text.str();
parser(crip);
//std::cout << crip << std::endl;
keyF.open(keyName, std::ifstream::in);
if(!keyF.good()){
std::cout << "Nao foi possivel abrir o dicionario" << std::endl;
return 0;
}
//TODO: if filter returns accepted print key and text in file
std::getline(keyF, aux);
keys << aux;
key = keys.str();
crip = playfair(crip, key, CRYPT);
std::cout << crip << std::endl;
return 0;
}
void parser(std::string &text){
text.erase(std::remove(text.begin(), text.end(), ' '), text.end());
std::transform(text.begin(), text.end(), text.begin(), ::tolower);
}
cachorro
......@@ -32,12 +32,12 @@ std::string playfair(std::string text, const std::string key, int crypt){
crypt=crypt+5;//Avoid operator % on negative numbers
std::ostringstream ret;
std::vector< char > mKey(createKM(key));
for (int i=0; i<5; ++i){
/*for (int i=0; i<5; ++i){
for (int j=0; j<5; ++j){
std::cout << mKey[i*5 + j] << ' ';
}
std::cout << std::endl;
}
}*/
unsigned int indexT = 0;
while(indexT <text.size() ){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment