Initialized initially as 0
Then first time through the loop it is 0 ( This part works correct )
Then next iteration of loop it has flipflop++; which increments +1 ( This part works correct )
After its done processing for that loop in which the value is 1, the value is switched back to 0 with
IF(flipflop==1){
flipflop=0;
}
And this part doesnt work and for such one of the most basic of instructions I hit this problem months ago and it was frustrating in how this should switch flipflop to 0 if flipflip is 1, but it wasnt doing that.
Now here is where it gets really weird... I didnt change the placement of where the flipflop is reset in the program. And I tried using modulus even as a means to have even where mod = 0 and odd having mod = 1 and that didnt work. I said what if I set the value to -1 and compiled and ran it and all of a sudden it was working.
Here below is the latest program that is built upon my first. I ran into problems with the conversion from what i had initially to ASCII calls, so I stuck with the long list of IF statements to test the input character and then assign it a value reference to a shuffled crypt as a 1 for 1 replacement.
In this newest code there are 2 crypts and it alternates between use of crypt key 1 and crypt key 2. With this the character A substituted with say X would only be X at say every odd array element in which there is an A to substitute for in the input string that is to be jumbled and cryptic. My first program was just a 1 for 1 replacement and so it was pretty easy to break and see the message knowing that every character that is the same represents the same character substitution. With the newer more complex program that uses 2 crypt keys to generate the cryptic output A and X wont represent the same character so
AVAILABLE in my first program was
X5
X:#
X8k!
AVAILABLE in my second program is
X5
X:#
$8k!
The colored letters/characters representing where A is in each output. A to be X A has to land at a odd interval, whereever A lands at an even interval it is no longer X but instead it is $ since $ is from the second crypt key and same array element placeholder as the first. So if A was 1 then Array 1 element 1 is X and Array 2 element 1 is $
Also very cool on sharing the
flipflop = !flipflop;
method. Ive never seen this trick done before. Question i have with its use is if its only good for 010101 pattern or if you can use a value specification with its use to get say 012301230123 etc? For years I have used the Increment and IF reset method.
Here is the entire program below. The part that might be confusing is the key strength part. If you use a value such as 9 it will use a weak key. 9 states that 9 characters can be the same between the original character from the string and the crypt output. Some shuffles have characters that stay in their original place within the array. I added this test for shuffle strength I think after I shared my first program last year, so this might be new to anyone who remembers the first program. I wrote a smaller program that used this key strength object as a means to try to discover the worst keys in which I told it to run for 1 billion keys from 1 to 1 billion shuffles of the array and look for characters that remained in their original element location within the array. I found a few that had 14 characters that remained in their original location, but didnt find the worst shuffle possible in which it is possible to use a value as a key and the shuffle places every character back into their original position in which there is none of the input cryptic, it all would go in as Hello_World and it would be written to file was Hello_World. I was very curious if there was the worst shuffle of all within the first billion keys and if so, how many times it hit that worst of all shuffle in which nothing ever got shuffled. I then realized after running my AMD FX-8350 4Ghz 8-core computer for almost a week that the best means to avoid use of a horrible key would be instead to just have it test the key right then and there as its input by user. So the electric wasted through this process was heating my home last winter for a week, and at least i know that the first billion keys dont have the worst shuffle of all in which the input becomes the same as the output.
Additionally my program is single-threaded and I had it processing in 8 programs running with 125 million keys each in ranges from 1 to 125 million, 125 million and 1 to 250 million and 1, and so on in 8 groups each using a core of the 8-core CPU to process it all that much sooner vs 1 core of 8 pegged and it taking 8 times longer to get to 1 billion because all processing power not utilized.
After you put in 2 keys and it shows the 2 keys scrambled on the screen that it is going to use, you then type in whatever you want, however it does not support spaces and so underscores can be used as space holders. You then press the enter key when everything to scramble is typed and you will see it display characters from left to right, this can happen fast with a fast computer or slow if your on an Intel Atom or Pentium 4 computer. When you see this scrambled output to exit the program you press the [ ` ] key which is the key that the tilde key is but the other character that skips my mind as to its name. And press enter after pressing the [ ` ] key. This will then write the last character of the scramble to the data file that saves the message etc. You also will have 3 other files created. A counter file that is used to keep track of what was the last value to have them listed in the files and be able to know that data at line 5 goes with the 2 key files that are also line 5. So reassembly of the data requires you to have Key 1 and Key 2 from line 5 which goes with the data at line 5 in the data file. *Note: The program to unscramble/decrypt it is not contained within the main program. They are intended to be isolated as well as the keys and the data also isolated so that they can be physically separated and brought back together like pieces of a puzzle to get the messages back out from if you have the decrypt program, correct keys to put in and the data that needs to be unscrambled.
Reasoning behind this program is to take my very important data and put it on a thumb drive that I can store elsewhere and if my home burned to the ground I wouldnt lose this data. I use unique complex passwords with just about everything from banking to even online games that I dont want to get hacked etc. This data isnt safe on a cloud. I like having physical control of my data. I was for a while leaving a small notebook in my car with this data, but it was far too risky having something so easily read by another. I then put it on a thumb drive in my car with this data in a hidden location but the one day i realized I would be really scrambling to change passwords if this ever got lost ( fell out of car etc ) as well as if someone got their hands on a thumb drive say when getting an oil change and they are cleaning and they find it and pocket it the first thing they would want to do is see what is on it. I could have bank accounts cleaned out etc. So this is why I am working on making my own tool for my data to keep it safe. I plan on adding a salt program later to this that also adds extra characters so that makes the data even that much more difficult to crack not knowing the message length, character substitution not always the same, and what is real from what is noise in the data.
The IDE I am using btw is Bloodshed Dev C++ 4.9.9.2 in which I have been aware that this IDE could have bugs that I might face some day and maybe just maybe the way that this IDE is compiling my program the reset to 0 doesnt work unless you use -1.
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
using namespace std;
int main ()
{
long long int seed1=0;
long long int seed2=0;
int code1=0;
int run=1;
int again=1;
int test=1;
int writeenable=0;
int counter=0;
int intcheck=0;
int intcheck2=0;
char ch1;
char ch2;
int ST,ST2,match2,match3,flag;
int flipflop=0;
while(again==1){
system("color 8e"); // Black text with Yellow background
while(intcheck==0){
cout<<" XXXXXXXXXXXXXXXXXXXXXXXXXX \n\n";
cout<<" X Crypt Version 2.00C X\n\n";
cout<<" X Build 002 - 12/26/2016 X\n\n";
cout<<" XXXXXXXXXXXXXXXXXXXXXXXXXX\n\n\n";
cout<<" Enter Integer Seed 1: \n"; // Asks user to input integer seed
cout<<"\n\n";
cin >> seed1; // Input user seed1
cout<<"\n"<<" Enter Integer Seed 2: \n"; // Asks user to input integer seed
cout<<"\n\n";
cin >> seed2; // Input user seed2
cout<<"\n\n\n";
cout<<"Enter Key Strength Value\n\n";
cout<<"Note: 0 = complete scramble and 3 = 3 matching pairs in crypt\n\n";
cin>>flag;
// Seed 1 Test
// --------------------------------------------------------------------------
string str3="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()_-+=?<>:\\/~.,;[]\"\'";
string str4="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()_-+=?<>:\\/~.,;[]\"\'";
srand(seed1); // Allows user custom seeded starting algorithm position for random
random_shuffle(str4.begin(), str4.end()); // Shuffle the string
// -------------------------------------------------------------------------
ST=0;
match2=-1;
while(ST<=89){
if(str3[ST]==str4[ST]){
//cout<<str[ST]<<"\n";
match2++;
}
else{
}
ST++;
}
if(match2>=flag){
match2++;
intcheck=0;
system("cls");
system("color 4F");
cout<<" Warning: Crypt Key #1 Weak with [ "<<match2<<" ] matching characters \n";
cout<<" Please enter a different key\n\n\n";
}
else{
system("cls");
cout<<"Key #1 Approved\n\n\n";
intcheck=1;
}
// ----------------------------------------------------------------------
// } closed loop on 110 and prior, remains open on 200 and after
// Seed 2 Test
// --------------------------------------------------------------------------
string str5="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()_-+=?<>:\\/~.,;[]\"\'";
string str6="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()_-+=?<>:\\/~.,;[]\"\'";
srand(seed2); // Allows user custom seeded starting algorithm position for random
random_shuffle(str6.begin(), str6.end()); // Shuffle the string
// -------------------------------------------------------------------------
ST2=0;
match3=-1;
while(ST2<=89){
if(str5[ST2]==str6[ST2]){
//cout<<str[ST2]<<"\n";
match3++;
}
else{
}
ST2++;
}
if(match3>=flag){
match3++;
intcheck2=0;
system("cls");
system("color 4F");
cout<<" Warning: Crypt Key #2 Weak with [ "<<match3<<" ] matching characters \n";
cout<<" Please enter a different key\n\n\n";
}
else{
system("cls");
cout<<"Key #2 Approved\n\n\n";
intcheck2=1;
}
// ----------------------------------------------------------------------
}
system("color 8f"); // Black text with Yellow background
// Read in from text file the value for foldercounter variable
ifstream myfile("counter200.txt", ifstream::in);
while(myfile >> counter);
counter=counter+1;
//write value to pick up with next time program is run here
std::ofstream write ("counter200.txt", std::ofstream::out);
write << counter;
write.close();
//write value to pick up with next time program is run here
std::ofstream write2 ("Crypt200Key1.txt", std::ofstream::out | ios::app);
write2 <<"\n"<<counter<<" "<<seed1;
write2.close();
//write value to pick up with next time program is run here
std::ofstream write5 ("Crypt200Key2.txt", std::ofstream::out | ios::app);
write5 <<"\n"<<counter<<" "<<seed2;
write5.close();
//write value to pick up with next time program is run here
std::ofstream write3 ("Crypt200Data.txt", std::ofstream::out | ios::app);
write3 <<"\n"<<counter<<" ";
write3.close();
//Initialize Valid Characters for String Shuffle Output
//Note Bug corrected with blank space for \ by use of escape character proceeding
string str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()_-+=?<>:\\/~.,;[]\"\'";
srand(seed1); // Allows user custom seeded starting algorithm position for random
random_shuffle(str.begin(), str.end()); // Shuffle the string
cout<<"\n\n"<<"Crypt #1 String Key =\n\n";
cout << str << "\n\n\n"; // Output the shuffle sequence
//Pass String Output into an array to pair up pointer value with associated character
string tmp = str; //Pass str output to string tmp
char tab2[128]; // Memory Allocation for array population
strncpy(tab2, tmp.c_str(), sizeof(tab2)); //string copy tmp into tab2 array
tab2[sizeof(tab2) - 1] = 0;
//HERE #2
//Initialize Valid Characters for String Shuffle Output
//Note Bug corrected with blank space for \ by use of escape character proceeding
string str7="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()_-+=?<>:\\/~.,;[]\"\'";
srand(seed2); // Allows user custom seeded starting algorithm position for random
random_shuffle(str7.begin(), str7.end()); // Shuffle the string
cout<<"\n\n"<<"Crypt #2 String Key =\n\n";
cout << str7 << "\n\n\n"; // Output the shuffle sequence
//Pass String Output into an array to pair up pointer value with associated character
string tmp2 = str7; //Pass str output to string tmp
char tab20[128]; // Memory Allocation for array population
strncpy(tab20, tmp2.c_str(), sizeof(tab20)); //string copy tmp into tab2 array
tab20[sizeof(tab20) - 1] = 0;
cout<<"Enter Info to Crypt in correct case\n";
cout<<"To Exit Inner Program enter ( ` ) \n\n\n";
while(run==1){
cin>>ch1;
//supress write to file until 1 loop run ( bug fix for double character write )
if(writeenable==1){
if(flipflop==0){
//write value to pick up with next time program is run here
//string tab2;
std::ofstream write4 ("Crypt200Data.txt", std::ofstream::out | ios::app);
write4 << tab2[code1];
write4.close();
}
if(flipflop==1){
//string tab20;
std::ofstream write4 ("Crypt200Data.txt", std::ofstream::out | ios::app);
write4 << tab20[code1];
write4.close();
} // While FF1
} //write enable
else{
//do nothing and continue
}
writeenable=1; //enable write to file
if (ch1=='A'){
code1=0;
}
else if (ch1=='B'){
code1=1;
}
else if (ch1=='C'){
code1=2;
}
else if (ch1=='D'){
code1=3;
}
else if (ch1=='E'){
code1=4;
}
else if (ch1=='F'){
code1=5;
}
else if (ch1=='G'){
code1=6;
}
else if (ch1=='H'){
code1=7;
}
else if (ch1=='I'){
code1=8;
}
else if (ch1=='J'){
code1=9;
}
else if (ch1=='K'){
code1=10;
}
else if (ch1=='L'){
code1=11;
}
else if (ch1=='M'){
code1=12;
}
else if (ch1=='N'){
code1=13;
}
else if (ch1=='O'){
code1=14;
}
else if (ch1=='P'){
code1=15;
}
else if (ch1=='Q'){
code1=16;
}
else if (ch1=='R'){
code1=17;
}
else if (ch1=='S'){
code1=18;
}
else if (ch1=='T'){
code1=19;
}
else if (ch1=='U'){
code1=20;
}
else if (ch1=='V'){
code1=21;
}
else if (ch1=='W'){
code1=22;
}
else if (ch1=='X'){
code1=23;
}
else if (ch1=='Y'){
code1=24;
}
else if (ch1=='Z'){
code1=25;
}
else if (ch1=='a'){
code1=26;
}
else if (ch1=='b'){
code1=27;
}
else if (ch1=='c'){
code1=28;
}
else if (ch1=='d'){
code1=29;
}
else if (ch1=='e'){
code1=30;
}
else if (ch1=='f'){
code1=31;
}
else if (ch1=='g'){
code1=32;
}
else if (ch1=='h'){
code1=33;
}
else if (ch1=='i'){
code1=34;
}
else if (ch1=='j'){
code1=35;
}
else if (ch1=='k'){
code1=36;
}
else if (ch1=='l'){
code1=37;
}
else if (ch1=='m'){
code1=38;
}
else if (ch1=='n'){
code1=39;
}
else if (ch1=='o'){
code1=40;
}
else if (ch1=='p'){
code1=41;
}
else if (ch1=='q'){
code1=42;
}
else if (ch1=='r'){
code1=43;
}
else if (ch1=='s'){
code1=44;
}
else if (ch1=='t'){
code1=45;
}
else if (ch1=='u'){
code1=46;
}
else if (ch1=='v'){
code1=47;
}
else if (ch1=='w'){
code1=48;
}
else if (ch1=='x'){
code1=49;
}
else if (ch1=='y'){
code1=50;
}
else if (ch1=='z'){
code1=51;
}
else if (ch1=='1'){
code1=52;
}
else if (ch1=='2'){
code1=53;
}
else if (ch1=='3'){
code1=54;
}
else if (ch1=='4'){
code1=55;
}
else if (ch1=='5'){
code1=56;
}
else if (ch1=='6'){
code1=57;
}
else if (ch1=='7'){
code1=58;
}
else if (ch1=='8'){
code1=59;
}
else if (ch1=='9'){
code1=60;
}
else if (ch1=='0'){
code1=61;
}
else if (ch1=='!'){
code1=62;
}
else if (ch1=='@'){
code1=63;
}
else if (ch1=='#'){
code1=64;
}
else if (ch1=='$'){
code1=65;
}
else if (ch1=='%'){
code1=66;
}
else if (ch1=='^'){
code1=67;
}
else if (ch1=='&'){
code1=68;
}
else if (ch1=='*'){
code1=69;
}
else if (ch1=='('){
code1=70;
}
else if (ch1==')'){
code1=71;
}
else if (ch1=='_'){
code1=72;
}
else if (ch1=='-'){
code1=73;
}
else if (ch1=='+'){
code1=74;
}
else if (ch1=='='){
code1=75;
}
else if (ch1=='?'){
code1=76;
}
else if (ch1=='<'){
code1=77;
}
else if (ch1=='>'){
code1=78;
}
else if (ch1==':'){
code1=79;
}
else if (ch1=='\\'){ // Escape Character \ needed to allow \ check
code1=80;
}
else if (ch1=='/'){
code1=81;
}
else if (ch1=='~'){
code1=82;
}
else if (ch1=='.'){
code1=83;
}
else if (ch1==','){
code1=84;
}
else if (ch1==';'){
code1=85;
}
else if (ch1=='['){ // added 86 thru 89 in version 1.10
code1=86;
}
else if (ch1==']'){
code1=87;
}
else if (ch1=='\"'){
code1=88;
}
else if (ch1=='\''){
code1=89;
}
else if (ch1=='\`'){ //Escape Character \ before ` to exit
run=0; //Run = False at 0 and leaves while loop
}
else {
cout<<"Invalid Input = No Match\n\n";
system("color CF"); // White text with Red background
}
system("color 8b"); // Black text with Green background
// Display output
//string tab2; //why? `tab2' undeclared (first use this function)
//Key #1 crypt
if(flipflop==0){
cout<<tab2[code1];
}
//Key #2 crypt
if(flipflop==1){
cout<<tab20[code1];
}
if(flipflop==1){
flipflop=-1; //Flipflop -1 because setting back to 0 is broken
}
flipflop++; //starts at 0 and alternates 010101010101 for 2 keysets
}// end inner while loop
test=1;
while(test==1){
system("CLS");
cout<<"Enter ( Y ) to continue - or - ( N ) to end program\n\n\n";
cin>>ch2;
if (ch2=='N'||ch2=='n'){
// line return to file ( formatting purposes )
std::ofstream write4 ("Crypt200Data.txt", std::ofstream::out | ios::app);
write4<<"\n";
write4.close();
again=0;
test=0;
}
else if (ch2=='Y'||ch2=='y'){
// line return to file ( formatting purposes )
std::ofstream write4 ("Crypt200Data.txt", std::ofstream::out | ios::app);
write4<<"\n";
write4.close();
intcheck=0;
again=1;
test=0;
run=1;
writeenable=0; //reset write enable to start of 0
system("CLS");
}
else {
cout<<"Invalid Input, please choose Y or N \n\n";
test=1;
}
}
} // end outter while loop
system("CLS");
system("PAUSE");
//return EXIT_SUCCESS;
return(0);
}