delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/06/25/13:50:34

From: "iparker" <ianparker AT clara DOT net>
Newsgroups: comp.os.msdos.djgpp,comp.security.pgp.tech
Subject: public key information
X-Newsreader: Microsoft Outlook Express 4.72.3110.1
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Message-ID: <7EOc3.106$GA4.3417@nnrp3.clara.net>
Date: Fri, 25 Jun 1999 17:04:03 GMT
NNTP-Posting-Host: 195.8.77.14
X-Complaints-To: abuse AT clara DOT net
X-Trace: nnrp3.clara.net 930330243 195.8.77.14 (Fri, 25 Jun 1999 18:04:03 BST)
NNTP-Posting-Date: Fri, 25 Jun 1999 18:04:03 BST
Lines: 102
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

The file below is conventional encryption, could anyone out there tell me in
practical terms that an idiot can understand, how public key encryption
works??

             thanks        Ian    Parker


/*
Name:               filefrm3.c
Processor:          Intel 80xxx
Compiler:           BC v3
Compiler Directive: Autolink
Creation Date:      24 June 99
Author:             I Parker
Version:            1.00
Bugs:               no catch if someone enters invalid key
Description:        encrytion/decryption 11 bit
Usage:              filefrm3 <file you want to encrypt/decrypt>
Status:             freeware use this code at your own risk I accept no
liability
Revision History:
Notes:              This is quite low grade encryption but an interesting
example
                    note the o/p file name is set as out.bin. It works
because
                    the EXclusive OR function is the same as modulo2
addition,
                    which is when you have two binary numbers and add them
                    together without carries, then take the result and do
                    the same with one of the two originals (key) then you
                    get the second original back (plain language)
*/

#include <stdio.h>

void main(int argc,char *argv[])

{
FILE *in,*out;
int seedval;
char ch,key,encrypt;
char seed[5];                                    /* place to put i/p string
*/

unsigned long count,last;                                   /* byte counter
*/

if (argc != 2)
   {
   fprintf(stderr,"filefrm2 v1.0 Usage: filefrm3 <data> \n by I Parker\n");
   exit();
   }

if((in = fopen(argv[1], "rb"))==NULL)
   {
   fprintf(stderr, "Couldn't open file \"%s\".\n",argv[1]);
   exit();
   }
if((out = fopen("out.bin", "wb")) == NULL)
   {
   fprintf(stderr,"Can't create output file. \n");
   exit();
   }

printf("Enter a seed value between 0 - 32767\n");
scanf("%s",seed);                                    /* get seed value
string */
seedval = atoi(seed);                                 /* convert to a number
*/
srand((char) seedval);         /* set seed value into pseudo random
generator */

fseek(in,0L,SEEK_END);                               /* seek end of file */
 last = ftell(in);                            /* report size of file */
 for (count = 0L; count <= last; count++)     /* loop to end of file */
 {
  fseek(in, +count, SEEK_SET);         /* go forwards */
  ch = getc(in);                       /* get char from file */
                key = (char)rand() % 255;            /* get char from key
generator */
                encrypt = ch ^ key;                  /* encrypt file with
key */
                putc(encrypt,out);     /* put to encrypted/decrypted char to
file */

        }
fclose(in);
fclose(out);
}












- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019