Help with C Program for Implementing Cipher to String

  • Thread starter Thread starter SNOOTCHIEBOOCHEE
  • Start date Start date
  • Tags Tags
    Program
Click For Summary
SUMMARY

This discussion focuses on implementing a cipher in C that shifts characters in a string based on a numeric key. The program requires the user to input a numeric key and a string, with the output reflecting the shifted characters while preserving the case and ignoring numbers. Key concepts include using ASCII values for character manipulation, developing a function to shift characters, and handling character rotation. The suggested function, shift(char MyCharacter, int Offset), is essential for achieving the desired functionality.

PREREQUISITES
  • Understanding of C programming language syntax and structure
  • Familiarity with ASCII character encoding
  • Knowledge of functions and loops in C
  • Basic experience with character arrays in C
NEXT STEPS
  • Implement the shift(char MyCharacter, int Offset) function to handle character shifting
  • Research character rotation techniques for handling overflow in ASCII values
  • Explore how to read and manipulate character arrays in C
  • Learn about creating and using translation tables for character mapping
USEFUL FOR

This discussion is beneficial for C programmers, students learning about character manipulation, and developers interested in cryptography and encoding techniques.

SNOOTCHIEBOOCHEE
Messages
141
Reaction score
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
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.
 
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:

Similar threads

  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 43 ·
2
Replies
43
Views
8K
  • · Replies 34 ·
2
Replies
34
Views
4K
Replies
86
Views
4K
  • · Replies 3 ·
Replies
3
Views
4K
Replies
81
Views
8K
  • · Replies 10 ·
Replies
10
Views
6K
  • · Replies 40 ·
2
Replies
40
Views
4K
Replies
55
Views
7K