Reading encrypted text file in program!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xakzyy
    New Member
    • Sep 2013
    • 3

    #1

    Reading encrypted text file in program!

    Hello peeps!


    I need some help to decrypt my text file and make it able to read in my program..

    What I have programmed so far is to read the encrypted file, create a new file, decrypt it and read the newly created file..

    I need to decrypt the encrypted file without having to create a new file that reads the decrypted text..

    Well, Let me show you my code:

    P.S Most of the include is not needed and I already know that

    Visual studio 2010 Windows Form Application CLR

    Code:
    #pragma once
    
    
    #include "stdafx.h"
    #include <iostream>
    #include <fstream>
    #include <conio.h>
    #include <stdio.h>
    #include <iomanip>
    
    
    namespace EncryptandDecryptfiletest {
    
    
        using namespace System;
        using namespace System::ComponentModel;
        using namespace System::Collections;
        using namespace System::Windows::Forms;
        using namespace System::Data;
        using namespace System::Drawing;
        using namespace System::IO;
        using namespace std;
    
    
        private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
    
    
                     /*Decryption --- When program loads*/
    
    
                     char ch,mod;
                     char key = 97;
                     char name[100] = "Encrypted.txt";
                     char target[100] = "TTO.txt";
                     ifstream fin("Encrypted.txt", ios::binary); // Reading file
                     if(!fin) //open the encrypted file in a binary mode
                     {
                         MessageBox::Show("Encrypted.txt did not open"); //If file does not exist
                     } //or any kind of error
                     
                     ofstream fout;
                     fout.open(target,ios::binary); //Opens outputfile
                     if(!fout)
                     { //Show error if any error occurs in opening new file
                         MessageBox::Show("TTO.txt did not open");
                     }
                     while(fin.get(ch))
                     { // opens the Encrypted file
                         if(ch==EOF)break;
                         mod = ch + key;
                         if (mod > 255 ) mod -= 255;
                         fout << mod; //Writes decrypted text to TTO.txt
                     }
                     fin.close(); //Close the encrypted file
                     fout.close(); // Close the decrypted file
                 }
        private: System::Void comboBox1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
    
    
                     label1->Text = comboBox1->Text;
                     pictureBox1->Load("Images\\" + comboBox1->SelectedItem->ToString() + ".png");
    
    
                     //String^ openFileTest = "Encrypted.txt"; // Opens the encrypted .txt file
                     String^ openFileTest = "TTO.txt"; //Opens the newly created file that is decrypted
    
    
                     try  //Reading the .txt file
                     {
                         StreamReader^ DataIn = File::OpenText(openFileTest);
                         String^ DataStr;
                         int count = 0;
                         array<String^>^ result;
                         array<Char>^ separ = gcnew array<Char>{'"'}; //After each Quote gets a new value of result[x]
    
    
                         while((DataStr = DataIn->ReadLine()) != nullptr)
                         {
                             count++;
                             result = DataStr->Split(separ);
                             if(comboBox1->Text == result[0]) // result[0] = Name
                             {
                                 textBox1->Text = result[1]; //reads first word in txt file
                                 textBox2->Text = result[2]; //second word in txt file
                                 textBox3->Text = result[3]; //third word in txt file
                             }
                         } // ends while()
                     } // ends try
                     catch (Exception^ e)
                     {
                         if(dynamic_cast<FileNotFoundException^>(e))
                             MessageBox::Show("File " + openFileTest + " not found");
                     }
                 } // Ends comboBox1_SelectedIndexChanged void
    };
    }
    You have my decryption code and the code I want to use..

    I have uploaded the code for you to use on your computer because it is fairly hard for me to explain..

    I want to be able to read the encrypted file in my program, without having to writing a new file to decrypt it..

    I hope anyone is able to help me

    Decrypted & Encrypted .txt file Included (And images)

    --> Program .rar pack link <--

    Build it with Visual Studio 2010
Working...