Results 1 to 6 of 6

Thread: Encryptor/decrypter

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2011
    Posts
    2

    Encryptor/decrypter

    Problem:
    Need to design a program that can encrypt and decrypt messages stored in simple text files using a private key stored in a separate file. Software should also be able to allow the users to enter simple messages that either displays the encrypted or decrypted message. The encryption method should use a simple substitution method. It should be set out in the following format:

    Example (the "@" is the separator):
    @
    The character The Code End of line
    A @ 4gh EOL
    B @ 84!9 EOL

    Has to use the 256 ASCII character codes. The separator will be used to separate the character and its corresponding code.
    Here are the pseudocodes I have come up with:


    • Read any private key file
    separator = readline(file);
    while not EOF(file) do
    tempStr = readline(file);
    tempArr = split(separator, tempStr);
    matchArr += tempArr[0];
    substitutionArr += tempArr[1];
    endwhile;
    • Allow users to enter messages (by entering text or file)
    string1 = user input from textbox

    • Encrypt and decrypt messages
    Encrypting:
    string1: get input from other module;
    length: length of string1;
    While Counter < length do;
    string2 += substitute from subarray(character(counter) of string1)
    endwhille;
    Decrypting:
    string1 = get input from other module;
    Length = length of string1;
    while counter < length do;
    string2 += substitute from matcharray(character(counter) of string1)
    endwhile;
    • Display encrypted/decrypted message
    textbox = string1
    • Print encrypted/decrypted message
    print encrypt (string1);
    print decrypt (string1);

    Can anyone point out if anything wont work/any fixes.

    Cheers
    -Ashur

  2. #2
    Fanatic Member ThomasJohnsen's Avatar
    Join Date
    Jul 2010
    Location
    Denmark
    Posts
    528

    Re: Encryptor/decrypter

    I didn't check out your code - just wan't to point out, that I think you're making this overly complex for yourself. First of all using substitutions with string matching functions (or Regex) will make encryption/decryption relatively slow on huge files. Not to mention your encrypted data will be up to 4 times as large as the non-encrypted portion (following you substitution for B).

    The framework has an entire namespace (System.Security.Cryptography) devoted to various common encryption routines, that may even be used in conjunction with any stream (ie. encrypting/decrypting of filestreams, networkstreams, memorystreams etc.), thus allowing you to encrypt/decrypt on the fly.

    I would advice you to have a look at those before implementing your own - I'm pretty sure, they will save you alot of work and even make your software a tad faster and more secure.

    Regards
    Tom
    In truth, a mature man who uses hair-oil, unless medicinally , that man has probably got a quoggy spot in him somewhere. As a general rule, he can't amount to much in his totality. (Melville: Moby Dick)

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Encryptor/decrypter

    Thomas - normally I'd agree... but that quote at the top reads like a homework assignment... Quite often this stuff is used to teach looping and string manipulation and how things can go bad very quickly... as evidenced by my final comments.

    first thing that jumps out at me is that your pseudocode is a little too detailed... you're using constructs that are language specific... the point of pseudocode is that it should be language agnostic... but that could also be just me.

    Displaying your string... should be string 2... not string 1... string 1 is your inputted message.

    you also need to include how you plan to increment Counter in your encrypt/decrypt routines... expecially if your encrypted replacements for each letter can be of a varying size.... which poses another problem...
    If, for example A = 123 but M is 23!45 and T is !456 .... and you end up with 123!456 .... is it 1 23!45 6 or 123 !456 or???? see the problem?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2011
    Posts
    2

    Re: Encryptor/decrypter

    @thomas: I'm doing this for school, but cheers for the feedback.

    Quote Originally Posted by techgnome View Post
    Thomas - normally I'd agree... but that quote at the top reads like a homework assignment... Quite often this stuff is used to teach looping and string manipulation and how things can go bad very quickly... as evidenced by my final comments.

    first thing that jumps out at me is that your pseudocode is a little too detailed... you're using constructs that are language specific... the point of pseudocode is that it should be language agnostic... but that could also be just me.

    Displaying your string... should be string 2... not string 1... string 1 is your inputted message.

    you also need to include how you plan to increment Counter in your encrypt/decrypt routines... expecially if your encrypted replacements for each letter can be of a varying size.... which poses another problem...
    If, for example A = 123 but M is 23!45 and T is !456 .... and you end up with 123!456 .... is it 1 23!45 6 or 123 !456 or???? see the problem?

    -tg
    Thanks for your reply! This was exactly the type of feedback I was looking for and yes your right about it being an assignment.

    I think i've fixed the displaying and incremental problems, but the other I do not know. A separator is to be used to distinguish the size of the code but I don't know if where I placed it is correct ? Here's the code.

    • Read any private key file
    separator = readline(file);
    while not EOF(file) do
    tempStr = readline(file);
    tempArr = split(" ", tempStr); //changed from separator to " "
    matchArr += tempArr[0];
    substitutionArr += tempArr[1];
    endwhile;
    • Allow users to enter messages (by entering text or file)
    string1 = user input from textbox

    • Encrypt and decrypt messages
    Encrypting:
    string1: get input from other module;
    length: length of string1;
    While Counter < length do;
    string2 += substitute from subarray(character(counter) of string1) until separator //changed to until separator
    endwhille;
    Decrypting:
    string1 = get input from other module;
    Length = length of string1;
    while counter < length do;
    string2 += substitute from matcharray(character(counter) of string1) until separator //changed to until separator
    endwhile;
    • Display encrypted/decrypted message
    textbox = string2 //changed string1 to string2

    • Print encrypted/decrypted message
    print encrypt (string2); //changed string1 to string2
    print decrypt (string2); //..

  5. #5
    Fanatic Member ThomasJohnsen's Avatar
    Join Date
    Jul 2010
    Location
    Denmark
    Posts
    528

    Re: Encryptor/decrypter

    Quote Originally Posted by techgnome View Post
    Thomas - normally I'd agree... but that quote at the top reads like a homework assignment... Quite often this stuff is used to teach looping and string manipulation and how things can go bad very quickly... as evidenced by my final comments.
    Ah - sorry ashur16. Was just trying to help
    In truth, a mature man who uses hair-oil, unless medicinally , that man has probably got a quoggy spot in him somewhere. As a general rule, he can't amount to much in his totality. (Melville: Moby Dick)

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Encryptor/decrypter

    @ashur16 - jsut for future reference... if you do post something that is homework related... please note this. It clears up any confusion... it also changes how people will respond... while we won't (generally... there are a few that don't have any scrupples) do people's homework for them, we will help with the nudging and feedback. It also changes how we provide that feedback, as we'll try not to introduce a potential concept that you may not have encountered yet.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width