One time Keyfile pad program help

closed account (LEwpfSEw)
I'm currently stuck at encrypting/decrypting a plaintext file using a keyfile that is made up from the creator and stored in the debug--> bin file location for use later.

My program works the command line prompt. I'm having a really hard time forming a code that takes another file to compare to the file inputted to decrypt or encrypt.


The user would put in something like this in the command line:

addcyph -e keyfile < clear > code

or

addcyph -d keyfile < code

Can someone please give me a boost or a helping hand. Thank you so much.


This is my starting frame of the code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <fstream>
#include <string.h>
#include <cstdlib>

using namespace std;


int main(int argc, char *argv[])
{
    bool bDecode = true;
    int  iCryptKey = 1;
    int  index = 0;
    int  ch = 0;

    for (int i=0; i<argc; i++)
    {
        if (strcasecmp(argv[i],"-d") == 0)
        {
            // decode
            bDecode = true;
        }
        else if (strcasecmp(argv[i],"-e") == 0)
        {
            // encode
            bDecode = false;
        }
        else
        {
            // Algorithm for encyrpyting or decrypting is here
            /*iCryptKey = atoi(argv[i]);*/

        }
    }

    index = 0;

    do
	{
         ch = cin.get() ;
         if (index % iCryptKey == 0)
         {
            cout.put(ch) ;
         }
         index++;
	} while ( ! cin.eof()) ;
}
Last edited on
I don't see you open any file in your programme.

Aceix.
closed account (LEwpfSEw)
Hi Aceix,

Thank you for your reply. Sorry, I should have been more clear. The file is opened in the command prompt line with the feed in symbol " < ".

For example, from my first post.

The user would put in: addcyph -e keyfile < clear > code

"addcyph" would be my program
"-e" would = to encode the file that was streamed in or it could be "-d" to decode
"<" = to stream in the file
"clear" = is the plaintext to encode
">" = output the file
"code" = the outputted encoded text file.


I have a file called "keyfile" which is filled with random characters to be used as the "keypad" or "keyfile" in this type of program and the file.txt is stored in my debug\bin folder for use. It matches it self with the streamed in file to encode it or decode it using the One time pad algorithm which could be found here:

https://en.wikipedia.org/wiki/One-time_pad

Last edited on
Topic archived. No new replies allowed.