-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode.c
More file actions
36 lines (31 loc) · 802 Bytes
/
encode.c
File metadata and controls
36 lines (31 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "A3header.h"
/*
* Program name: encode.c
* Author: Rehan Nagoor Mohideen
* Student ID: 1100592
* Purpose: Function to encode a character by a shift and give out the character after the shift.
*/
int encode(char character, int shiftVal){
int newChar = character;
if ((character) > 64 && (character < 91)) {
newChar = character + shiftVal;
if (newChar > 90) {
newChar = 64 + (newChar - 90);
}
if (newChar < 65) {
newChar = 91 + (newChar - 65);
}
}else if ((character > 96) && (character < 123)) {
newChar = character + shiftVal;
if (newChar > 122) {
newChar = 96 + (newChar - 122);
}
if (newChar < 96) {
newChar = 123 + (newChar - 97);
}
}
return newChar;
}