• Starting today August 7th, 2024, in order to post in the Married Couples, Courting Couples, or Singles forums, you will not be allowed to post if you have your Marital status designated as private. Announcements will be made in the respective forums as well but please note that if yours is currently listed as Private, you will need to submit a ticket in the Support Area to have yours changed.

  • CF has always been a site that welcomes people from different backgrounds and beliefs to participate in discussion and even debate. That is the nature of its ministry. In view of recent events emotions are running very high. We need to remind people of some basic principles in debating on this site. We need to be civil when we express differences in opinion. No personal attacks. Avoid you, your statements. Don't characterize an entire political party with comparisons to Fascism or Communism or other extreme movements that committed atrocities. CF is not the place for broad brush or blanket statements about groups and political parties. Put the broad brushes and blankets away when you come to CF, better yet, put them in the incinerator. Debate had no place for them. We need to remember that people that commit acts of violence represent themselves or a small extreme faction.
  • We hope the site problems here are now solved, however, if you still have any issues, please start a ticket in Contact Us

  • The rule regarding AI content has been updated. The rule now rules as follows:

    Be sure to credit AI when copying and pasting AI sources. Link to the site of the AI search, just like linking to an article.

Jan 22, 2004
69
4
37
PA
✟209.00
Faith
Protestant
Well, I'm so proud of my baby. It's still in testing. If you see any bugs let me know. It's a simple encryption program for Windows. I had dome some work with .so in Linux, so I figured I'd give .dll files a shot. Here is all the code, ans a Makefile. I compliled it with MinGW (a GCC port for WIndows) with no warnings other than about a def file.

main.c:
Code:
#include <stdio.h>
#include <stdlib.h>
#include "main.h"
#include "xordll.h"

int main(int argc, char *argv[])
{
  int choice = -9;

  choice = menu();

  switch (choice)
    {
    case 1:
      {
	xordlle();
	main(argc, argv);
	break;
      }
    case 2:
      {
	xordlld();
	main(argc, argv);
	break;
      }
    case 3:
      {
	puts("Not yet implemented");
	exit(EXIT_FAILURE);
	break;
      }
    case 4:
      {
	puts("Good-bye");
	puts("www.kgivler.com/KGD");
	puts("Coded by PunkCow");
	exit(EXIT_SUCCESS);
	break;
      }
    default:
      {
	fprintf(stderr, "This line should never be seen! Quitting\n");
	exit(EXIT_FAILURE);
	break;
      }
    }

  exit(EXIT_SUCCESS);
}

int menu(void)
{
  int choice = -2;

  while(choice < 1 || choice > 4)
  {
    printf("\nKGDenc version %s\n", VER);
    puts("\n1.) XOR encrypt");
    puts("2.) XOR decrypt");
    puts("3.) About");
    puts("4.) Exit");

    printf("\nPlease make a selection: ");
    scanf("%d", &choice);
  }
  return choice;
}

main.h:
Code:
#if defined( MAIN_H_ )
/* included */
#else
#define MAIN_H_

#define VER "0.2b (unstable beta)"

int menu(void);
const char about[] = "KGDEnc coded by PunkCow";

#endif

fexist.h:
Code:
#if defined( FEXIST_H )
/* already included */
#else
#define FEXIST_H

int file_exists(char *filename);

#endif

fexist.c:
Code:
#include <stdio.h>
#include <stdlib.h>
#include "fexist.h"

int file_exists(char *filename)
{
  /* Returns TRUE if exists, FALSE if not */
  FILE *fp;
  if ((fp = fopen(filename, "r")) == NULL)
    return 0;
  else
    {
      fclose(fp);
      return 1;
    }
}
 
  • Like
Reactions: Lost
Jan 22, 2004
69
4
37
PA
✟209.00
Faith
Protestant
newgets.h:
Code:
#if defined( NEWGETS_H )
/* Already included */
#else
#define NEWGETS_H

void new_gets(char *str, int len);

#endif

newgets.c:
Code:
#include <stdio.h>
#include <stdlib.h>
#include "newgets.h"

void new_gets(char *str, int len)
{
  int index;

  fgets(str, len, stdin);

  for (index = 0; index < len; index++)
    if (str[index] == '\n')
      {
	str[index] = 0;
	return;
      }
}

xordll.h:
Code:
#if defined ( XORDLL_H_ )
/* already included */
#else
#define XORDLL_H_
#define XORVER "0.2b (unstable/buggy beta)"

const char xorabout[] = "Coded by PunkCow";

 #ifdef BUILD_DLL
   // the dll exports
 #define EXPORT __declspec(dllexport)
 #else
   // the exe imports
  #define EXPORT __declspec(dllimport)
  #endif

   // function to be imported/exported
EXPORT void xordlle (void);
EXPORT void xordlld (void);

#endif
 
Upvote 0
Jan 22, 2004
69
4
37
PA
✟209.00
Faith
Protestant
xordll.c:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "xordll.h"
#include "newgets.h"
#include "fexist.h"

EXPORT void xordlle(void)
{
  int key = -99;
  int enc = 0;
  int ch;
  FILE *in, *out;
  char filename[253];
  char outname[256];

  printf("\n\nKGDxor version %s\n", XORVER);
  puts("Please enter the name of the file you wish to encrypt:");
  while ((ch = getchar()) != '\n' && ch != EOF);
  new_gets(filename, 253);

  printf("\nPlease enter the key to encrypt with. This key is needed for decryption.\n");
  printf("The key must be an INTGER from -2000000000 to 2000000000");
  printf("\nKey: ");
  scanf("%d", &key);

  if (key < -199999999  || key > 199999999)
    {
      fprintf(stderr,"\nYou can't use that key\n");
      fprintf(stderr,"TODO: Better error handeling\n");
      fprintf(stderr,"QUITTING!\n");
      exit(EXIT_FAILURE);
    }

  strcpy(outname, filename);
  strcat(outname, ".xor");


  /* VERY ugly file checks, there has to be a better way */
  if(!file_exists(filename))
    {
      fprintf(stderr, "Input file %s not found, did you make a typo?\n", filename);
      fprintf(stderr, "TODO: Nicer error handeling\n");
      fprintf(stderr, "STOPPING HERE\n");
      exit(EXIT_FAILURE);
    }

  if((in = fopen(filename, "rb")) == NULL)
    {
      fprintf(stderr, "Error opening %s in binary read mode\n", filename);
      fprintf(stderr, "STOPPING HERE\n");
      exit(EXIT_FAILURE);
    }

  if(file_exists(outname))
    {
      fprintf(stderr, "Output file %s already exists!!\n", outname);
      fprintf(stderr, "TODO: Nicer error handeling\n");
      fprintf(stderr, "STOPPING HERE\n");
      exit(EXIT_FAILURE);
    }

  if((out = fopen(outname, "wb")) == NULL)
    {
      fprintf(stderr, "Error opening %s in binary write mode\n", outname);
      fprintf(stderr, "STOPPING HERE\n");
      exit(EXIT_FAILURE);
    }
 /* PHEW... End of UGLY file checks... Is there a better way?? */

  /* The guts of the program */
  while(1)
    {
      enc = fgetc(in);
      if(!feof(in))
	{
	  enc = enc ^ key;
	  fprintf(out, "%d ", enc);
	}
      else
	break;
    }
  /* End of the guts */

  puts("\nFile succesfuly encrypted!");

  fclose(in);
  fclose(out);

  char del[200];
  puts("Delete orignal file? (Y)es/(N)o?");
  scanf("%s", del);

  if (del[0] == 'y' || del[0] == 'Y')
    {
      if(remove(filename) == 0)
	{
	  printf("\nFile %s deleted (but not wiped)!\n", filename);
	}
      else
	{
	  fprintf(stderr, "\nError deleting file\n");
	  return;
	}
    }
  else
    {
      puts("\nfile not deleted");
    }
  

  return;
}

EXPORT void xordlld(void)
{
  int key = -99;
  int enc = 0;
  FILE *in, *out;
  char filename[256];
  char inname[256];
  int ch;

  printf("\n\nKGDxor version %s\n", XORVER);
  printf("Name of file to decrypt (without .xor)?\n");
  while ((ch = getchar()) != '\n' && ch != EOF);
  new_gets(filename, 256);

  strcpy(inname, filename);
  strcat(inname, ".xor");

  if(file_exists(filename))
    {
      fprintf(stderr, "File %s already exists, please re-name or delete it", filename);
      fprintf(stderr, "TODO: Nicer/better/smarter error handeling\n");
      fprintf(stderr, "EXITING NOW!\n");
      exit(EXIT_FAILURE);
    }

  printf("\nIf you use the wrong key, the file will be un-readable\n");
  printf("What is the key the file was encrypted with (an intger)?\n");
  printf("Key: ");
  scanf("%d", &key);

  /* VERY ugly file checks, there has to be a better way */
  if(!file_exists(inname))
    {
      fprintf(stderr, "Input file %s not found, did you make a typo?\n", inname);
      fprintf(stderr, "TODO: Nicer error handeling\n");
      fprintf(stderr, "STOPPING HERE\n");
      exit(EXIT_FAILURE);
    }

  if((in = fopen(inname, "rb")) == NULL)
    {
      fprintf(stderr, "Error opening %s in binary read mode\n", inname);
      fprintf(stderr, "STOPPING HERE\n");
      exit(EXIT_FAILURE);
    }

  if((out = fopen(filename, "wb")) == NULL)
    {
      fprintf(stderr, "Error opening %s in binary write mode\n", filename);
      fprintf(stderr, "STOPPING HERE\n");
      exit(EXIT_FAILURE);
    }
 /* PHEW... End of UGLY file checks... Is there a better way?? */

  /* The guts */
  while(1)
    {
      fscanf(in, "%d ", &enc);
      if(!feof(in))
	{
	  enc = enc ^ key;
	  fprintf(out, "%c", enc);
	}
      else
	break;
    }
  /* end if guts */

  printf("\nThe file was decrypted. If the file is un-readable, then you most likely used the wrong key.\n");

  fclose(in);
  fclose(out);

  return;
}

and a Makefile...

Makefile:
Code:
main : main.o
	dllwrap --output-lib=libxordll.a --dllname=xor.dll --driver-name=gcc xordll.o newgets.o fexist.o
	gcc -o kgdenc main.o -L./ -lxor

main.o : main.c main.h xordll.h xordll.o newgets.o fexist.o fexist.h
	gcc -Wall -c main.c

xordll.o : xordll.c xordll.h
	gcc -c -Wall -DBUILD_DLL xordll.c

fexist.o : fexist.c fexist.h
	gcc -c -Wall fexist.c

newgets.o : newgets.c newgets.h
	gcc -c -Wall newgets.c

#  gcc -c hello.c
#  gcc -c -DBUILD_DLL dllfct.c
#  dllwrap --output-lib=libtstdll.a --dllname=tst.dll --driver-name=gcc dllfct.o
#  gcc -o hello.exe hello.o -L./ -ltstdll

I think that's it. If I missed a file let me know. If you see any bugs I'd be thankfull if you pointed them out.

TIA!
 
Upvote 0