Help with C Program for Implementing Cipher to String

  • Thread starter SNOOTCHIEBOOCHEE
  • Start date
  • Tags
    Program
In summary, you should search for a function that takes in an input of characters and shifts them by a certain amount, and also have a reverse function.
  • #1
SNOOTCHIEBOOCHEE
145
0
Ok I am having trouble writing this program in C.

Basically what i have to write is a program that implements a cipher to a string of text.

So it will ask the user to imput a Numeric key (lets say for instance 4)
and a string of text (I.E ABCDEFG)

and the output will be

EFGHIJK

it has to do that for upper and lower case stuff, and leave numbers alone.

Now i have a general idea of how to do it. I am guessing you basically have to get the computer to recognize the ACSII code for each character, and develop a function that adds the numeric key value to each character. Problem is i have no clue how to do this.


Any ideas/help?
 
Technology news on Phys.org
  • #2
The ASCII code for upper case letteres are 65 to 90 and lower case letters are 97 to 122, numbers are from 48 to 57. So you should search through the text string by using a loop and look for ASCII codes lying in these intervals and take action depending on which interval you are in.
 
  • #3
SNOOTCHIEBOOCHEE said:
Now i have a general idea of how to do it. I am guessing you basically have to get the computer to recognize the ACSII code for each character, and develop a function that adds the numeric key value to each character. Problem is i have no clue how to do this.
You read the input in an array of characters right. So think of how you can cast each character to something that you can manipulate as a number and then cast back to a character.

An elegant solution would be to make a function called for instance shift(char MyCharacter, int Offset) which returns the shifted character. Obviously you would want the function to rotate as well when applicable and also be able to use negative numbers.

If you enjoy it you could for instance add a reverse (char [] MyString) function that reverses the string. Or a decode(char [] Mystring, char [][] TranslationsTable) function. The TranslationsTable would simply describe the mapping from one letter to another one.

Have fun!
 
Last edited:

What is a cipher?

A cipher is a method of transforming plain text into a secret code to protect its contents from being read by anyone other than the intended recipient.

Why would I need to implement a cipher in a C program?

Implementing a cipher in a C program can be useful for protecting sensitive data or messages, as well as for learning about encryption techniques and computer programming.

What is the most commonly used cipher in C programs?

The most commonly used cipher in C programs is the Caesar cipher, which involves shifting the letters of a message by a certain number of positions in the alphabet.

Do I need any special knowledge to implement a cipher in a C program?

Basic knowledge of C programming language and data structures is necessary to implement a cipher in a C program. A good understanding of algorithms and encryption techniques would also be helpful.

Are there any resources available to help with implementing a cipher in a C program?

Yes, there are many online tutorials, forums, and code libraries available to help with implementing a cipher in a C program. It is also recommended to consult with an experienced programmer or computer scientist for guidance and assistance if needed.

Similar threads

  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
34
Views
2K
  • Programming and Computer Science
Replies
9
Views
3K
  • Programming and Computer Science
Replies
10
Views
2K
  • Programming and Computer Science
3
Replies
81
Views
5K
  • Programming and Computer Science
2
Replies
55
Views
4K
  • Programming and Computer Science
Replies
3
Views
3K
  • Programming and Computer Science
2
Replies
41
Views
3K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
5
Views
605
Back
Top