From cdabc31333cb9d377260996f9c71b29737bb43c0 Mon Sep 17 00:00:00 2001 From: Thiago Monteles <37663376+thiagomonteles@users.noreply.github.com> Date: Sun, 7 Oct 2018 17:41:11 -0300 Subject: [PATCH] Name Encryption Exercise Name Encryption Exercise --- String/encrypt.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 String/encrypt.c diff --git a/String/encrypt.c b/String/encrypt.c new file mode 100644 index 0000000..2bf5eda --- /dev/null +++ b/String/encrypt.c @@ -0,0 +1,47 @@ +#include +#include + +void encryption(char *name); +int main() +{ + int n,i; + char str[128]; + + scanf("%[^\n]%*c",str); + + + printf("%s\n",str ); + return 0; +} + +void encryption(char *name){ + int i,c=0, countSTR; + + countSTR = strlen(name);//get the amount of the string + char aux[countSTR]; + + + //move all CHARACTERS in 3 characters to the right + for (i = 0; i < countSTR; i++){ + if ((name[i]>='A' && name[i]<='Z') || (name[i]>='a' && name[i]<='z')) name[i] = name[i]+3; + } + + //ssave the password in an auxiliary vector + for (i = 0; i < countSTR; i++){ + aux[i]=name[i]; + } + + //reverse the string + for (i = countSTR-1; i>=0 ; --i){ + name[c]=aux[i]; + c++; + } + + //view the amount of elements and save the amount of + countSTR = (int)(countSTR/2); + + //move the half (countSTR) of the characters to the left + for (i = countSTR; name[i]!='\0'; ++i){ + name[i] = name[i]-1; + } +}