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


ADVERTISEMENT

C++ :: Read Byte Of Char Data And Convert It Into Text String Of Binary Data That Represents Hex Value

Dec 26, 2013

I am writing a program where I need to read a byte of char data and convert it into a text string of binary data that represents the hex value...

i.e. The char byte is 0x42 so I need a string that has 01000010 in it. I've written the following subroutine....

------------- My Subroutine ----------------------------------------------------------------------
void charbytetostring(char input, char *output){
int i, remainder;
char BASE=0x2;
int DIGITS=8;
char digitsArray[3] = "01";

[Code] ....

When I submitted the byte 0x42 to the subroutine, the subroutine returned to the output variable 01000010... Life is good.

The next byte that came in was 0x91. When I submit this to the subroutine I get garbage out.

I am using a debugger and stepped through the subroutine a line at a time. When I feed it 0x42 I get what I expect for all variables at all points in the execution.

When I submit 0x91 When the line remainder = input % BASE; gets executed the remainder variable gets set to 0xFFFF (I expected 1). Also, when the next line gets executed..

input = input / BASE; I get C9 where I expected to get 48.

My question is, are there data limits on what can be used with the mod (%) operator? Or am I doing something more fundamentally incorrect?

View 6 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 :: Int Array To Char (Binary Value)

Jul 19, 2013

I have an int array with the binary value of a char. How to to turn it into a char? I can transform it to an int but then I'm stuck.

Code:
#include <stdio.h>
int main() {
int a[260] = {0,1,1,0,0,0,0,1};
char buf[260];
int b=0;
for(int i=0; i<8; i++) {
b=10*b+a[i];
}
itoa(b, buf, 10);

View 6 Replies View Related

C++ :: Clear Data From Char Array?

Feb 5, 2013

How to clear data from a char array?

View 19 Replies View Related

C++ :: Turn Binary File Data Into Unsigned Character Array For Inclusion In Executable

Jul 10, 2013

So I wrote a program to turn a binary file's data into an unsigned character array for inclusion in an executable. It works just super.

I'm wondering how I can write a program that will perform this operation on every file in a directory and all it's sub-directories so that I can I can include everything I need all at ounce.

View 9 Replies View Related

C :: Store Data In Binary File Then Use It To Find Inverse Of Matrix Form Of Data

Dec 6, 2013

I need to find inverse of a matrix data in binary file should be used to form matrix.its not finding inverse correctly rest is working good.

Code:
#include <stdio.h>
void createbin();
void display();
void inverse();
int main()
{
createbin();
display();
inverse();

[Code] ....

View 4 Replies View Related

C :: Binary File Write By User Input Then Printing Binary File Data Out

Dec 6, 2013

Following is the program I wrote it basically takes 9 inputs and then save them into binary file. then print out the data stored in binary data and find inverse of it then print the inverse out. but its stuck in a loop somewhere.

Code:
#include <stdio.h>
int main() {
int a[3][3],i,j;
float determinant=0;
int x;
FILE *fp = fopen ("file.bin", "wb");

[Code] .....

View 6 Replies View Related

C++ :: Binary Char Pointer Into String

Jun 12, 2013

Is there a more simple method to copy Buf into str? Buf is a binary string.

Code:
void function(string & str) {
int iWholeSize = 512;
char * Buf = new char[iWholeSize];
.... operations on Buf
string s(Buf, Buf + iWholeSize);
str = s;
}

View 5 Replies View Related

C++ :: Char Pointers And Random Binary Files

May 6, 2013

I'm new with working with random binary files. I have a class with a char* pointer stored inside of it, I also have a constructor that takes in a string (of any size) from the user. I then simply store this string into the char *. Once the string is stored in the char *. I reinterpret the instance, and I store the information into the random binary file. Everything works.

Question: Random files must know the size of the object that is being stored inside of it, so why when I enter strings of different sizes into the file, it appears to still be working. for example this is an example of the code:

class info {
private:
char *phrase;
public:
info(string n ="unknown"){
phrase = new char[n.size()+1];

[Code] ....

My point is, lets just say for example the object ETC, was some long string, this would still work for me. My question is, I don't believe each object is the same size because I allocate memory for the char pointer in the constructor.

Should I not do this just to be safe, and just use a char array instead of a pointer? (Even tho I would have set a pre-defined size for the string) or is something happening in the back to prevent this from not working?

View 5 Replies View Related

C++ :: Comparing Char Array To Char Always Returns True

Dec 23, 2014

I've made a code to check whether or not a save file has been created correctly, but for some reason it always returns this line: readdata[qa]=='1' as true. in which qa is the counter I use in a for loop and readdata is a character array consisting of 50 characters that are either 0, 1 or 2.

this is the entire code:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code]....

at first is also went wrong at line 22 and also returned that as true, but then I added brackets and it worked.

View 4 Replies View Related

C++ :: Concatenate Two Char Arrays Into Single Char Array?

Sep 29, 2014

I am trying to concatenate two words from a file together. ex: "joe" "bob" into "joe bob". I have provided my function(s) below. I am somehow obtaining the terminal readout below. I have initialized my memory (I have to use dynamic, dont suggest fixing that). I have set up my char arrays (I HAVE TO USE CHAR ARRAYS (c-style string) DONT SUGGEST STRINGS) I know this is a weird way to do this, but it is academic. I am currently stuck. My file will read in to my tempfName and templName and will concatenate correctly into my tempName, but I am unable to correctly get into my (*playerPtr).name.

/* this is my terminal readout
joe bob
<- nothing is put into (*playerPtr).name, why not?
joe bob joe bob
seg fault*/
/****************************************************************/
//This is here to show my struct/playerInit

[Code]....

View 2 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 :: Char Array With A Phrase To Char Word

Nov 28, 2013

I need to do a function that copy every word from a text to a char word. How can i do it?

View 5 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

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++ :: 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 View Related

C :: Getting Int Data From Char

Apr 4, 2013

developing an algorithm with use of minimum system resources. I have an embedded board with sends data through rs232 port to system.

the moment i give the command it starts transmiting data to my pc(buffer array) Now the first 317 bytes are read as strings and i am able to get that read successfully.

The rest of the data is to be read in int form.i.e 2 bytes(short int) short quick way to read int data without much manipulation(which may cause loss of data as baudrate is very high).

Here is what i have going so far: Code: ///Reading Data
// while(rzBuff[0] != '
')
for(i=0;i<=318;i++)

[Code].....

View 4 Replies View Related

C++ ::  Send Binary Data Over TCP/IP

Sep 3, 2014

I am writing a client-server program in C++ using C libraries. The server listens for a connection and when one is found, it is supposed to send a binary file(an image in my case) to the client. The server is sending the binary file perfectly after opening it and reading its contents into a buffer that is dynamically allocated in the SERVER file.

The problem begins when the client file is supposed to recv() the file, I do not know how I can allocate a buffer big enough for the file to be received. I know how to use malloc() and new, I prefer malloc() for executable size customization. Assuming the file being sent is 11000 bytes(note that this is an assumption and the client can not know the file size because the file size is dynamically generated by server).

How can the client generate a dynamically allocated buffer big enough to hold 11000 bytes?
OR
How can the client store the data in a buffer using recv() without knowing the file size.

Below is part of the code that does the send()'ing and recv()'ing.

SERVER

FILE *img = fopen("img.jpg", "rb");
fseek(img, 0, SEEK_END);
unsigned long filesize = ftell(img);
char *buffer = (char*)malloc(sizeof(char)*filesize);
rewind(img);
// store read data into buffer

[Code] ....

This outputs all the binary code perfectly but it is a bug because it can't be written to a file. Is there a way to dynamically increase the buffer until all filesize is received? Certainly, buffer needs to be dynamically allocated or program crashes ...

Also one more thing, when I telnet the server from command line, telnet displays all the output perfectly as well

Maybe telnet is storing data into a buffer behind the scenes, if so, how?

View 9 Replies View Related

C++ :: Char Data Type Variable

Jun 12, 2013

I have two char variables, m_GPSOffset[13] and m_FileName[100]. When m_GPSOffset has a value assigned to it, say for instance +11:25:30. The first entry of the value, in this case +, is always stored in m_FileName. I am clueless on why this is occurring.

View 15 Replies View Related

C :: Converting Binary Data In A Txt File Into HEX

Apr 17, 2013

I'm not the best at C but I'm trying to write a C function that basically opens a text file with assembler language does a syntax error check on it and then converts the binary data into hex.

This is my code so far:

Code:

#include <stdio.h>
#include <string.h>
int main(void)
{
FILE*fname;
char prompt;
char filename[15];
char text[100];
printf( "Please enter the name of the file you wish to open: " );

[Code]...

View 6 Replies View Related

C++ ::  writing Binary Data On Txt File?

Aug 16, 2013

I a want to write a code to convert a string into binary data for that i wrote a code its working perfectly but there is one problem , some of the binary data is written in 7bit and i want to convert it to 8 bit by adding 0 to the last.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code]....

View 2 Replies View Related

C++ :: Pointers / Binary Data And Shifting

Sep 15, 2014

unsigned short foo = 1337;
//since unsigned short is 2 bytes, a char x[2]should be enough to hold the binary data
char foo2[2];

How do I have foo2, contain the binary equivalent of foo? (how can I point foo2 to = &foo)

View 4 Replies View Related







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