-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencrypt.cpp
80 lines (79 loc) · 2.36 KB
/
encrypt.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// richu shaji abraham
#include<fstream>
#include<stdio.h>
#include<iostream>
#include "random.h"
long long int read_file_to_memmory(FILE *pInfile , int *pPointer)
{
if(pInfile != NULL)
{
int mIndex =0;
int mSize = fread(pPointer+mIndex,1,sizeof(int),pInfile);
long long int mFileSize=0;
while(mSize!= 0)
{
mFileSize = mFileSize +mSize;
++mIndex;
mSize = fread(pPointer+mIndex,1,mSize,pInfile);
}
return mFileSize;
}
return 0;
}
long long int write_file_from_memmory(FILE *pOutFile , int *pPointer,long long int pFileSize)
{
if(pOutFile!=NULL)
{
pFileSize = fwrite(pPointer,1,pFileSize,pOutFile);
return pFileSize;
}
return 0;
}
long long int generate_random_bits(int *pPointer , long long int pSize)
{
long long int mSize = pSize;
long long int mIndex =0;
while(pSize>0)
{
(*(pPointer+mIndex)) = rand();
++mIndex;
pSize = pSize - sizeof(int);
}
return mSize;
}
long long int generate_encrypted(int *pDataPointer , int *pRandomData, int *pEncryptedData, long long int pSize)
{
long long int mSize = pSize;
long long int mIndex =0;
while(pSize>0)
{
(*(pEncryptedData+mIndex)) = (*(pDataPointer+mIndex))^(*(pRandomData+mIndex));
++mIndex;
pSize = pSize - sizeof(int);
}
return mSize;
}
int main(int argc , char *argv[])
{
FILE *inFile;
FILE *outFile;
FILE *keyFile;
inFile = fopen("c.html","rb");
outFile = fopen("enc","wb");
keyFile = fopen("key","wb");
int *dataPointer = new int[268435456];
std::cout<<"yo";
long long int fileSize = read_file_to_memmory(inFile,dataPointer);
std::cout<<fileSize;
int *randomBytePointer = new int[fileSize/sizeof(int) + 100];
fileSize = generate_random_bits(randomBytePointer , fileSize);
std::cout<<"hello2";
int *encryptedPointer = new int[fileSize/sizeof(int) +100];
fileSize = generate_encrypted(dataPointer,randomBytePointer,encryptedPointer,fileSize);
std::cout<<"hello";
fileSize =write_file_from_memmory(outFile,encryptedPointer,fileSize);
fileSize =write_file_from_memmory(keyFile,randomBytePointer,fileSize);
fclose(inFile);
fclose(outFile);
fclose(keyFile);
}