1 Replies - 7371 Views - Last Post: 27 May 2013 - 01:06 PM

#1 Tyler_911  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 28
  • Joined: 01-June 07

[Experts Only] Encryption not decrypting?

Posted 27 May 2013 - 12:25 PM

Well let me start off on explaining what i'm doing. I want to bind a bunch of files together and encrypt it. when ran the files should be decrypted by the stub file and then the stub saves my files to a directory and my C++ application that is using the files will use them using python embedding.

Anyways here is the Application:
Posted Image

The code for "button 1" is:
private void btnBuild_Click(object sender, EventArgs e)
        {
            using (BinaryWriter fileWriter = new BinaryWriter(File.Open(Application.StartupPath + @"\build.exe", FileMode.Create), Encoding.Default))
            {
                Oblivion obliv = new Oblivion();
                BinaryReader stubReader = new BinaryReader(File.Open(txtStub.Text, FileMode.Open), Encoding.Default);
                byte[] stubData = new byte[stubReader.BaseStream.Length];
                stubReader.Read(stubData, 0, (int)stubReader.BaseStream.Length - 1);

                string[] stubContent = txtStub.Text.ToString().Split('\\');

                fileWriter.Write(stubData);
                fileWriter.Write("@@##" + stubContent[stubContent.Count() - 1] + "@@##");

                stubReader.Close();
                for (int i = 0; i < lstBind.Items.Count; i++)
                {
                    string[] contents = lstBind.Items[i].ToString().Split('\\');
                    
                    BinaryReader fileReader = new BinaryReader(File.Open(lstBind.Items[i].ToString(), FileMode.Open), Encoding.Default);
                    byte[] fileBuffer = new byte[fileReader.BaseStream.Length];

                    fileReader.Read(fileBuffer, 0, (int)fileReader.BaseStream.Length - 1);

                    fileWriter.Write(obliv.Exec_Cipher(fileBuffer, Convert.ToInt32(txtCrypt.Text)));
                    fileWriter.Write("@@##" + contents[contents.Count() - 1] + "@@##");

                    fileReader.Close();
                }
                fileWriter.Close();
            }


        }


Oblivion.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace testProject
{
    class Oblivion
    {
        public byte[] Exec_Cipher(byte[] data, int key)
        {
            byte[] b = new byte[data.Length];
            b = data;

            for (int n = 0; n < b.Length; n++)
            {
                b[n] = (byte)(b[n] ^ key);
            }

            return b;
        }
    }
}



I'm pretty sure it encrypts but when it comes to decrypting it doesn't work. Can you see any flaws so far? If this doesn't help I will post my Stub file after. But I just need help understanding why Exec_Cypher shouldn't do the exact same thing and decrypt if I called it.

edit: oh no, i've seemed to posted in the wrong section! Moderators!!! please move please!!

This post has been edited by Tyler_911: 27 May 2013 - 12:26 PM


Is This A Good Question/Topic? 0
  • +

Replies To: [Experts Only] Encryption not decrypting?

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10445
  • View blog
  • Posts: 38,683
  • Joined: 27-December 08

Re: [Experts Only] Encryption not decrypting?

Posted 27 May 2013 - 01:06 PM

Closing this one. Please avoid duplicate posting. In the future, please just report your thread rather than reposting. It creates less confusion.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1