ASCII format encrypted file Xlmw$mw$e$weqtpi$mrtyx$jmpi$jsv$GSWG$587: ewwmkrqirx$'542$]syv$tvskveq$wlsyph$irgshi$xlmw jmpi$f}$ehhmrk$jsyv$xs$xli$EwGMM$zepyi$sj$iegl$ glevegxiv$mr$mx2$Mr$}syv$irgshih$jmpi$xli$jmvwx$glevegxiv$wlsyph$ fi$+\+2$Xli$pewx$glevegxiv$sj$xli$jmvwx$pmri$wlsyph$fi$+>+2 Xli$irgshih$jmpi$wlsyph$lezi$<$pmriw$sj$xi|x$nywx$pmoi$xlmw$sri0 fyx${mpp$fi$yrviehefpi2$Xli$pewx$glevegxiv$sj$xli$pewx$pmri${mpp$ fi$e$+6+2 I have to decode this code.txt file and here is what I have got so far, help int main() { char ch; string str; ifstream inputFile; ofstream outputFile; inputFile.open("coded.txt"); outputFile.open("plain2.txt"); while (!inputFile.eof()) { getline(inputFile, str); inputFile.get(ch); while (ch != '\n') { ch = ch - 4; outputFile.put(ch); inputFile.get(ch); } } inputFile.close(); outputFile.close(); return 0; }
djblade · Dec 8, 2014 1:12 PM · 17,834 views
$ are spaces, fyi
djblade · Dec 8, 2014 6:18 PM
Please help, anybody?
djblade · Dec 9, 2014 12:05 AM
I don't know if this will help you in your assignment. I can't write in C++, but here is the algorithm that I would use to write in my choice of language. 1. declare a string with alphabets, s = "abcd....z" 2. read the characters in your code one by one and count them 3. The most frequently used letter is 'e' (roughly 12%) 4. based on that I would find the rotation of the character in your code. By rotation I mean find the index of your character in the string 's' and subtract index of e, in this case it is 4. 5. Now shift each of your characters by that rotation, but leave the punctuations and blank spaces as they are. 6. After decoding see if it makes sense. This might not work in your code, but you can give it a try. Hope that helps
Sparty · Dec 9, 2014 11:14 AM
By the way using the language that I use, I could partially decode it. Here is the decoded part if that helps this is a sample input file for cosc 587: assignment '542 ]our program should encode this file b} adding four to the ascii value of each character in it2 in }our encoded file the first character should be +\+2 the last character of the first line should be +>+2 the encoded file should have < lines of te|t just like this one0 but {ill be unreadable2 the last character of the last line {ill be a +6+2 I think the algorithm that I mentioned earlier needs some refinement, but you got the point that I was trying to convey. Good luck with your assignment
Sparty · Dec 9, 2014 11:56 AM
4 is the key?
prankster · Dec 9, 2014 12:17 PM
I have the encrypted file in code.txt which is in same directory as source.cpp file. My code is supposed to ifstream encoded file and subtract 4 form ASCII value of each character. The output of the decoded file will in turn be stored in same directory as file plain2.txt
djblade · Dec 9, 2014 12:23 PM
you do the reading from file part, I just assigned input the variable, #include using namespace std; int main() { char c[] = "Xlmw$mw$e$weqtpi$mrtyx$jmpi$jsv$GSWG$587:ewwmkrqirx$\'542$]syv$tvskveq$wlsyph$irgshi$xlmwjmpi$f}$ehhmrk$jsyv$xs$xli$EwGMM$zepyi$sj$iegl$glevegxiv$mr$mx2$Mr$}syv$irgshih$jmpi$xli$jmvwx$glevegxiv$wlsyph$fi$+\+2$Xli$pewx$glevegxiv$sj$xli$jmvwx$pmri$wlsyph$fi$+>+2Xli$irgshih$jmpi$wlsyph$lezi$<$pmriw$sj$xi|x$nywx$pmoi$xlmw$sri0fyx${mpp$fi$yrviehefpi2$Xli$pewx$glevegxiv$sj$xli$pewx$pmri${mpp$fi$e$+6+2"; for (int i = 0; i< sizeof c; i ++) { char decodedString = c[i] - 4; cout << decodedString; } return 0; } The output was: This is a sample input file for #10. Your program should encode our to the AsCII value of each c our encoded file the first chara he last character of the first l e encoded file should have 8 lin
prankster · Dec 9, 2014 12:28 PM
If you want to learn file handling in c++, http://www.tutorialspoint.com/...
prankster · Dec 9, 2014 12:32 PM
Seems the output got truncated, here is the correct output, This is a sample input file for COSC 1436assignment #10. Your program should encode thisfile by adding four to the AsCII value of each character in it. In your encoded file the first character should be '. The last character of the first line should be ':'.The encoded file should have 8 lines of text just like this one,but will be unreadable. The last character of the last line will be a '2'.�
prankster · Dec 9, 2014 12:37 PM
Prankster bro, hands down you are the best. Genius
djblade · Dec 9, 2014 2:09 PM
This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.
Start a New Discussion