Jump to content
Lasiaf

Encrypt-decrypt

Recommended Posts

er.... bleh mintak tlg x?? kalo aku buat satu string.. pastu nak encryptkannya..

cth:

char[34] a=blablabla

void encrypt(a);

paham tak??... aku cuma tak dapat lagi cara² nak encrypt sesuatu char

ribuan terima kasih untuk yang membantu....

biggrin.gif

Share this post


Link to post
Share on other sites

#include <stdio.h>

#define PROG_NAME "xe"
void usage()
{
printf("-------------------------------n");
printf("Invalid command line.n");
printf("Usage:nt%s infile outfile keyn", PROG_NAME);
printf("-------------------------------n");
}


int main(int argc, char *argv[])
{
int count,bytes; /* counter when looping through file, and bytes to count filesize */
FILE *in,*out; /* In and out FILE Streams to read/write data */

if(argc < 4) { /* Error check the command line */
usage(); /* Display Usage Information on error */
return 0; /* Exit Program returning 0 - no error */
}

if (( in = fopen(argv[1], "rb")) == NULL) /* Error Check File Streams */
{
printf("Error opening %s.n", argv[1]);
}
if (( out = fopen(argv[2], "wb")) == NULL)
{
printf("Error opening %s.n", argv[2]);
}


while(( count = getc(in)) != EOF) 
{
count = count ^ *argv[3]; /* Apply XOR ( KEY ) */
bytes++; /* Increment counter of filesize */
putc(count, out); /* Write new file */
}

fclose(in);
fclose(out);
printf("Encryption Success:n");
printf("tEncrypted %s and stored data in %s.n", argv[1],argv[2]);
printf("tWrote %d bytes to %s.n", bytes,argv[2]);
return 0;
}



cilok!

Share this post


Link to post
Share on other sites

A'kum. deeja, cam penah tgk jer koding tuh. kalo tak silap aku ada satu tutorial yg kat internet tu kan? aku penah wat, tapi tak menjadik, tapik dah lama la... aku sajer nak menerai...

Share this post


Link to post
Share on other sites

Tima kasih suma..... aku akan berusaha... dapat aku bagitau.... ade presentation skang ni.... siut tul la sesat plak.... singgah jap kat lab ni... baru sekali ponteng..he he he he²³²²

Share this post


Link to post
Share on other sites

ok deejagothic... tima kasih atas kod tu.. aku dah try kat lab ni... guna Borland C++ v 5.01 tak salah aku la.. jadi... buat satu fail ntxe.cpp .. copy source dan compile... 3 warning message..

guna dos@cmd taip kat folder yang ade menatang ni...

ntxe nama_fail_yg_ko_nak_encryptkan nama_fail_baru 1-255

1-255 untuk xor...

kalo nak decryptkan... function sama....

10101<your text

01010<no encrypt<------

------- l

11111<encrypt l-----kena sama nombor....

v l

11111<encrypt text l

01010<no encrypt <----l

-------

10101<decrypt

biggrin.gif

Share this post


Link to post
Share on other sites

Tima kasih suma..... aku akan berusaha... dapat aku bagitau.... ade presentation skang ni.... siut tul la sesat plak.... singgah jap kat lab ni... baru sekali ponteng..he he he he²³²²

hmmm.. kecoh laaa.. laugh.giflaugh.giflaugh.gif

pi mengajo ker?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...