The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
YAR? 3
Posted by: WHOEVS | March 16, 2011 @ 8:12pm
C++ Code
[
Download
]
#include <iostream> #include <strstream> #include <fstream> //header file for file i/o, contains data types // ifstream, ofstream, open, close #include <string> //header file for string manipulation operations using namespace std; //The CharacterShift Function takes in the Key //and the Cipher value (both chars) //and decrypts them as per this projects //request and it will also return a blank space //if the cipher is a blank space char CharacterShift(char Key, char Cipher); string Decryption(string CipherArray, string KeyArray); void IOFunction(); int main(){ IOFunction(); return 0; } char CharacterShift(char Key, char Cipher) { char output; if(Cipher==' ') { return Cipher; } Key = Key - 65; Cipher = Cipher - 65; if( Key > Cipher) { output = 91+Cipher-Key; } else { output = 65 + (Cipher-Key); } return output; } string Decryption(string KeyArray, string CipherArray){ int TemporaryCount=0; int i=0; string New; int CipherArrayLength=CipherArray.length(); int KeyArrayLength=KeyArray.length(); for(i;i<CipherArrayLength;i++){ if(CipherArray[i]=='?'){ New+='?'; } if(CipherArray[i]=='\''){ New+='\''; } if(CipherArray[i]=='%'){ New+='\n'; New+='\n'; } if(CipherArray[i]=='.'){ New+='.'; } if(TemporaryCount>=KeyArrayLength){ TemporaryCount=0; } if(CipherArray[i]==' '){ New+=' '; } if(TemporaryCount<KeyArrayLength && CharacterShift(KeyArray[TemporaryCount],CipherArray[i])!=' '&&CipherArray[i]!='.' ){ New+=CharacterShift(KeyArray[TemporaryCount],CipherArray[i]); TemporaryCount++; } } return New; } void IOFunction(){ string junk,Key1,Cipher1,Key2,Cipher2; string TotalText; string myFileName; //variable to hold external file name ifstream inFile; //internal file (stream) name cout <<"Please enter your input file name:"; cin >> myFileName; inFile.open(myFileName.c_str()); //convert to c_string and opens file // if open does not work, inFile is in a �fail� state while (!inFile) // therefore !inFile will be �true� { inFile.clear(); //puts the file states back to �good� from bad open cout << endl << "You entered an invalid file name. Please try again:"; cin >> myFileName; inFile.open(myFileName.c_str()); } while (inFile) //�true� if the open command executed properly { getline(inFile,junk,'@'); getline(inFile,Key1,'#'); getline(inFile,Cipher1,'@'); getline(inFile,Key2,'#'); getline(inFile,Cipher2,'@'); } if(junk.length()>1){ cout<<"*** Error Code 2 -- No key given ***"<<endl; } inFile.close(); cout<< Decryption(Key1, Cipher1); cout<< Decryption(Key2, Cipher2); }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.92 / 8
59 Votes
http://codebin.yi.org/1173
page generated in 0.00 seconds