Jump to content
  • Announcements

    • alpenwasser

      Please Use CODE Tags   31 Jan 2016

      Welcome to the Programming and Software Design Section,

      When asking for help with programming issues, please use the code tags to enclose your code, it makes things much more easily readable for the people trying to help you, thus improving your chances of actually getting help.
        To add code tags, click the <> button on the editor toolbar, then enter your code in the code editor that appears. If you are on a mobile device, or prefer to use BBCode, you can use [code] // Your code here // It will be syntax highlighted, though not necessarily corectly. [/code] (but the code editor is more consistent and less buggy).
Aztec

Trying to do cipher decryption using C

Recommended Posts

Posted · Original PosterOP

Hi, I'm trying to decrypt a ".txt" file using C language (cipher method). I keep getting loads of errors during compiling. Can someone please help me? Thanks! 

Code:

#include<stdio.h>
#include<stdlib.h>
#define MAX_SIZE 256 

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

*argv=[1], argv=[2]);
FILE *in_file, out_file;

in_file= fopen(argv[1], "r");
out_file= fopen(argv[2], "w");

void counter()

    char str[MAX_SIZE];
    int i, len;
    int freq[26];

    gets(%i);

    len = strlen(str);

    for(i=0; i<26; i++)
    {
        freq = 0;
    }

    for(i=0; i<len; i++)
    {

        if(str>='a' && str<='z')
        {
            freq[str - 97]++;
        }
        else if(str>='A' && str<='Z')
        {
            freq[str - 65]++;
        }
    }

char data[50], temp;
int key, count;

void shuttleSort(int a[], int n) {
    int i = 1, j;
    int temp;
    while (i < n) {
        j = i - 1;
        while (j >= 0) {
            if (a[j] > a[j + 1]) {
                temp = a[j];
                a[j] = a[j + 1];
                a[j + 1] = temp;
                j--;
            } else {
                break;
            }
        }
        i++;
    }
    printf("\n");
    printf("\nThe sorted array elements are given below\n");
    for (i = 0; i < n; i++) {
        printf("a[%d]=%d ", i, a);
    }
}
 void shuttle sort
    int i, n = 6;
    int a[] = {15, 8, 17, 12, 38, 19};
    printf("\n:: Shuttle Sort ::\n");
    printf("\nInput array elements\n");
    for (i = 0; i < n; i++) {
        printf("a[%d]=%d ", i, a);
    }


void caesar_cipher_decryption()
{
      for(count = 0; data[count] != '\0'; count++)
      {
            temp = data[count];
            if(temp >= 'a' && temp <= 'z')
            {
                  temp = temp - key;
                  if(temp < 'a')
                  {
                        temp = temp + 'z' - 'a' + 1;
                  }
                  data[count] = temp;
            }
            else if(temp >= 'A' && temp <= 'Z')
            {
                  temp = temp - key;
                  if(temp < 'A')
                  {
                        temp = temp + 'Z' - 'A' + 1;
                  }
                  data[count] = temp;
            }
      }
      printf("\nDecrypted Message:\t%s\n", data);
}

Link to post
Share on other sites

Here's the immediate problems I see

  • main doesn't have an end curly brace, or it does and it's encapsulating everything, which in the context of the rest of the source, is not allowed because nested function definitions aren't allowed in C.
  • Closing parenthesis at the statement *argv=[1], argv=[2]);
    • Also this statement makes no sense.
  • Functions counter and shuttle_sort don't have curly braces encapsulating the function
    • There's also another function called shuttleSort... so which one are you using?
  • Declaration of data[50], temp, key, and count are ambiguous in terms of scope. Are they global to the source, local to a function, what?
  • Not checking to make sure argv is of correct size before proceeding (what if I call the program with no arguments?)

I'm not going to re-write the source for you, but maybe someone who's more generous than me will.

Edited by M.Yurizaki
Link to post
Share on other sites
Posted · Original PosterOP
6 hours ago, M.Yurizaki said:

Here's the immediate problems I see

  • main doesn't have an end curly brace, or it does and it's encapsulating everything, which in the context of the rest of the source, is not allowed because nested function definitions aren't allowed in C.
  • Closing parenthesis at the statement *argv=[1], argv=[2]);
    • Also this statement makes no sense.
  • Functions counter and shuttle_sort don't have curly braces encapsulating the function
    • There's also another function called shuttleSort... so which one are you using?
  • Declaration of data[50], temp, key, and count are ambiguous in terms of scope. Are they global to the source, local to a function, what?
  • Not checking to make sure argv is of correct size before proceeding (what if I call the program with no arguments?)

I'm not going to re-write the source for you, but maybe someone who's more generous than me will.

Thank you. I've got a code that detects the letters and then one that shuttle sorts them and then the decrypt. I'm fairly new to C language as you can probs tell haha.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.


×