C++ :: Gather Input From User And Encrypt / Decrypt Those Characters?

Jan 5, 2015

I have got to create a program that will gather input from the user and then encrypt & decrypt those characters.

I'm not very confident at coding so I'm sure many parts of my code are written poorly and not following the best practice so I have written a simple version of an algorithm where the program simply adds/subtracts a value of 2 to/from the ASCII values but I have discovered the use of the rand() and srand functions but I'm unsure how to go about using them within both my encrypt and decrypt function as a single value (static variable?).

Here is my code in its entirety at the moment.

#include <iostream >
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <fstream>
using namespace std;
char getMenuSelection (char m);
void encrypt (char key[]);
void decrypt (char code[]);

[code]....

This code currently doesn't execute due to ' undefined reference to 'encrypt(char*) '

Question

I am asking how to generate the random number and incorporate this into my encrypt and decrypt functions.

1. Would the use of a static or global variable make this work as is?

2. Would I need to create separate class files for both functions?

View 2 Replies


ADVERTISEMENT

C++ :: Gather All Input Data And Write To A File

Dec 13, 2014

I'm trying to use a function to gather all inputted data and write that data to a file. I'm having trouble getting it to work.

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>

using namespace std;

int totalExpenses(double[], double, string, int);
int totalIncome(double);

[Code] ....

View 1 Replies View Related

C :: Read Characters From User Input And Construct A String

Mar 13, 2013

how to read characters from user and construct a sting and then extract part of it using substring?

View 2 Replies View Related

C++ :: Prompt User For Two Characters - Output Movies That Begin With Input

Nov 24, 2014

I have trouble printing out the movies starting with inputing only two letters.

#include <iostream> //cout, cin, endl,getline
#include <fstream> //ifstream
#include <cstdlib> // exit
using namespace std;

const int NUM_MOVIES = 116792;
struct Movie {

[Code] ....

View 1 Replies View Related

C++ :: Input Validation - Prevent User From Entering Characters Or Symbols Instead Of Numbers?

Jul 19, 2013

How do I prevent user from entering characters or symbols instead of numbers?
int num;
cout<<"Enter a number."<<endl;
cin>>num;

Also, how do I prevent user from entering a number instead of a character?
char c;
cout<<"Enter a character."<<endl;
cin>>c;

View 9 Replies View Related

C++ :: Number X Is Encrypted - Decrypt Function?

Jun 19, 2014

I am to use this cipher in which the number x is encrypted

(a and c are known numbers)

Also, what will the decrypt function be? Actually, i need to find the decryption formula...below is the code i tried to test...

char x = 'a';
cout<<x1<<endl<<x2<<endl;
cout<<x1<<endl<<x2<<endl;

View 6 Replies View Related

Visual C++ :: Decrypt Exe File That Is Encrypted?

Nov 20, 2014

i have an executable that is encrypted; it is made in Visual C++. decrypt it? what i must to look for? I have some kind of files (.req extention) that have the content encoded by password type.

View 2 Replies View Related

C :: Linked List To Gather Student Info

Dec 17, 2014

The programme has to be a linked list to gather student info, (ie name, lastname, student no, and three grade); the first and last name must use malloc correctly, there must be an insert and delete function and a printfunction. and they must print out in alphabetical order.

Code:
#include #include #include struct student{
char *lastName;
char *firstName;
char dob[20];
char sID[20];
float grade;

[code] .....

View 7 Replies View Related

C++ :: How To Stop Input After Certain Characters

Oct 23, 2013

I'm trying to get the user to input their 5 digit zip code but my problem is how can I stop the program after the five characters have been inputted. Also how can I only get numbers to be inputted cause so far letters can be inputted as well.

View 2 Replies View Related

C++ :: User Array Size And Sorting User Input

Nov 1, 2014

I am making program that allows the user to determine how big the array size will be and then asks the user to make up numbers to fill the array. Every time run the program on Dev C++ it says "program has stopped working"

Heres My Code:

//Assignment 19 Program 2
#include <iostream>
using namespace std;
int main()

[Code].....

View 3 Replies View Related

Visual C++ :: Showing Time For A User While Entering Some Characters

Dec 26, 2014

Im working on my project for college and i want to know how to add sth similar to a chronometer for user to see how much time have passed while entering some characters using cin.getline function.

View 2 Replies View Related

C++ :: Pushing Characters Back Into The Input Buffer?

Mar 29, 2013

I plan to read one character at a time from a very large text file.

The tokens that I would like to extract are basically words and they are delimited by varying numbers of spaces or tabs.

For example, the first line has two words separated by five spaces:

Joe Mark

Problem:I apply get() each time advancing towards Mark. For me to know ive reached the next token, Mark, I merely have to get() until it equals 'M'. The problem by then its too late as Ive already captured 'M'. I somehow need to capture the fifth space and the code must "know" the next character is 'M' without getting() it.

Kernighan and Richie offer us a function getch() and ungetch() whereby the ungetch pushes back the last character into the input . The problem with this is that I believe is that the buffer is not the actual input buffer stream but rather a simulated character array which contains the input. I dont think itll be as efficient on a text file so large.

View 9 Replies View Related

C/C++ :: How To Put Characters To Array And Compare To File Input

Mar 17, 2015

I am trying to generate possible combinations of 4 lower case letters from aaaa - zzzz. The words will then be used against a file that contains encrypted passwords that each relate to a 4 lower case word. I have successfully generated the words. Now all i need to do is put the created words (aaaa, aaab, etc...) to an array so I can use crypt((array[i+1]), buff) and print the encrypted 4 letters that come from the file. I am having a lot of trouble complete this though.

New problems that are occurring

The main problem is in the all function and main. I'm not wanting to print the aaaa, aaab, aaac, etc to the screen but I want to put it in an char array so that i can compare each individually to each line from the file using crypt. How to put all 456976 combinations into an array, compare it to each line of code, and print the solutions to the screen.

File:

$1$6gMKIopE$I.zkP2EvrXHDmApzYoV.B.
$1$pkMKIcvE$WQfqzTNmcQr7fqsNq7K2p0
$1$0lMKIuvE$7mOnlu6RZ/cUFRBidK7PK.

Code:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>

[Code]....

View 1 Replies View Related

C/C++ :: How To Encrypt The Password To Be Inputted

Sep 14, 2014

#include<stdio.h>
#include<conio.h>
#include<string.h>
char str1[20], str2[20]="kent";
main() {
printf("Enter your Username: ");
scanf("%s",str1);

[Code] ....

View 1 Replies View Related

C :: Counting Function - Prints All Input Lines That Are Longer Than 80 Characters

Jan 10, 2014

I'm doing an exercise that prints all input lines that are longer than 80 characters. I rather not use any libraries so I decided to write my own function that counts characters to use it in my main program. However when integrate things my function returns zero all the time.

Here is my full code:

/* Exercise 1-17 Write a program to print all input lines that are longer than 80 characters */

#include<stdio.h>
/* Declarations*/
#define MAX_STRING_LEN 1000
int count_characters(char S1[]);
int main() {

[Code] .....

So I was trying to debug my count_characters() function and this is the code if I was to run it seperately:

Code:
#include <stdio.h>
/* counts character of a string*/
main() {
int nc = 0;
int c;
for (nc = 0; (c = getchar()) != '
'; ++nc);
printf("Number of characters = %d
", nc);
}

which works...

View 1 Replies View Related

C++ :: How To Encrypt TXT Document Using Caesar Encryption

Mar 1, 2013

so i need to encrypt a txt document using Caesar encryption. however i don't know how to open a txt and shift the keys into a new txt. the program has to ask the user for the number it should shift. Using arrays, if else. i also need to make a menu so i am using switch.

View 4 Replies View Related

C :: Program Attempts To Encrypt A File Using XOR Operator?

Mar 18, 2013

My program attempts to encrypt a file using XOR operator. However, when I attempt to encrypt a file, it says "Error in reading file", (a printf function I set up if the program could not read the file, obviously). The problem is that I don't know what's causing this. Instead of encrypting the file, it just deletes all the characters in it, so I put in a fprintf to put place some text into the file. Here is the code:

Code:

#include<stdio.h>
#include<string.h>
int encryptd(FILE *);
int main(void)
{
FILE *fileptr;
int recode;
char fname[25];

[Code]...

View 7 Replies View Related

C :: Program In Which Computer Will Read Txt File And Encrypt It

Jan 1, 2014

I am writing a program in which the computer will read a txt file and encypt it. The encryption works fine, but the computer cannot read the file perfectly. If there's a newline, the scanning process stops. For example I have the following text in the txt file.

One two three four five
(newline) Six seven eight

The computer will stop reading after 'five'. I assume that is because I use fgets.

View 4 Replies View Related

C++ :: How To Make Own Binary Trees And Encrypt Messages

Jun 8, 2013

I'm having some trouble with my binary tree for school. It is a data structures class so we are working on learning how to make our own binary trees and encrypt messages. Everything so far is working, except for my delete node function. I'm trying to do it recursively. Parts of my code.

/******** Node *********/
struct node {
char data;
node* right;
node* left;
};
/******** Binary Tree Class *********/
class BinaryTree

[Code]...

View 5 Replies View Related

C++ :: Encrypt Char Array With Binary Data

Apr 14, 2013

I am trying to encrypt a char Array with binary data.

I think I understand the basic of Encryption / Decryption but I fail to see how to implement something.

I am trying to have a "key" that needs entered so the data can become readable executable. The program I am encrypting is a small console window with a message with the text "A secret message from your friend" (Not that it matters).

I have the binary data witch I can copy and what not. But how go about Encryption and then decrypt it and not destroying the data.

View 6 Replies View Related

Visual C++ :: Create A Function Using Rot To Encrypt Strings

Sep 30, 2013

I need to create a function using rot to encrypt certain strings the function begins like this

#include "encrypt.h"
std::string encrypt (std::string text, int rot) {
for (int i
and ends like this
return NULL;
}

dont need to write the string encrypted and dont need to crate a decrypt function.

View 4 Replies View Related

C :: Encrypt Message Within BMP File - Incorrect Struct Size

Feb 9, 2015

I'd wrote a program to encrypt a message within a bmp file using my own structs and all for everything (yes, call me a ........head) The program works but for some weird ........ing reason I was forced to subtract 2 bytes from the header size to get the correct value. I've narrowed down the issue to my BmpFileHeader struct.

Here's a short program that demonstrates the issue:

Code:
#include <stdio.h>
#include <stdlib.h>

#define BYTE unsigned char
#define WORD unsigned short
#define DWORD unsigned long
#define LONG signed int

[Code] .....

Tried with both gcc and TinyCC and got the same result so it doesent seem to be a compiler bug. Microsoft's structures though are giving the correct size, even though they have the exact same definition.

Microsoft's defines:

Code:
// windef.h
typedef unsigned long DWORD;
typedef unsigned char BYTE;
typedef unsigned short WORD;

[Code] .....

View 5 Replies View Related

C++ :: Second User Name Input Is Being Skipped

Jan 1, 2014

In this simple end-of-chapter problem, the ages of two people are to be compared and determine who's older. The problem I'm experiencing is that the second user name input is being skipped and going straight to the second users age.

So while running the program it looks something like:

What is user ones name?
<input name>
How old are they?
<input age>
What is user twos name?
How old are they?
<input age>
<if statement result>

Here's my code:

Code: #include <iostream>
#include <string>
using namespace std;
int user_one_age;
int user_two_age;
string user_one_name;
string user_two_name;

[code].....

View 9 Replies View Related

C# :: TexBox User Input To Hex Value

Sep 2, 2012

So I've got this form that a user puts in a numeric value into a text box. This value then has to be placed into a byte string of data so that it can be transmitted over as a packet. Bellow is what I have so far:

Code:
Byte[] OUTBuffer = new byte[65];//Allocate output memory buffer
Byte[] INBuffer = new byte[65]; //Allocate input memory buffer

if (setmSpeed == true)
{
OUTBuffer[0] = 0; //Not used, must be set to 0
OUTBuffer[1] = 0x85; //Command mode

[Code] ....

I've put in red the area where I'm having issues. I've tried different methods and have not been able to get this working yet. It only works if I speciffy the value manually as with OUTBuffer[1] = 0x85;, but I want byte 2 of OUTBuffer[] to be set with what I put in the text box.

View 4 Replies View Related

C :: User Input To File

Mar 18, 2013

I'm creating a program that should create a structure of a list of people entered by the user; the only problem I'm having is with the %c. When I have it, the loop only occurs once; if I put a %s, the loop occurs up to 25 times, but it doesn't write to the text file. Here is the code:

Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
[code]....

View 2 Replies View Related

C :: User Input With Forks

Apr 7, 2013

So im working with forks and creating 2 fork processes. One child and parent. What im trying to get the child to ask me for a value. Then the parent would start to figure out the value and keep trying. Once it figures it out its tells them you got it and simply stops the program. I cant seem to get the program to keep guessing and stop when the number is found which sends a sigint. Here's what i have so far.

Code:
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdbool.h>

int main() {
int j, i,pid;

[Code] .....

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved