[ad_1]
I’ve tested all of them and it worked I don’t what is the problem if you can help thanks in advance.
the check50 results:
:( encrypts "A" as "Z" using ZYXWVUTSRQPONMLKJIHGFEDCBA as key
expected "ciphertext: Z\...", not "ciphertext: Z"
:( encrypts "a" as "z" using ZYXWVUTSRQPONMLKJIHGFEDCBA as key
expected "ciphertext: z\...", not "ciphertext: z"
:( encrypts "ABC" as "NJQ" using NJQSUYBRXMOPFTHZVAWCGILKED as key
expected "ciphertext: NJ...", not "ciphertext: NJ..."
:( encrypts "XyZ" as "KeD" using NJQSUYBRXMOPFTHZVAWCGILKED as key
expected "ciphertext: Ke...", not "ciphertext: Ke..."
:( encrypts "This is CS50" as "Cbah ah KH50" using YUKFRNLBAVMWZTEOGXHCIPJSQD as key
expected "ciphertext: Cb...", not "ciphertext: Cb..."
:( encrypts "This is CS50" as "Cbah ah KH50" using yukfrnlbavmwzteogxhcipjsqd as key
expected "ciphertext: Cb...", not "ciphertext: Cb..."
:( encrypts "This is CS50" as "Cbah ah KH50" using YUKFRNLBAVMWZteogxhcipjsqd as key
expected "ciphertext: Cb...", not "ciphertext: Cb..."
:( encrypts all alphabetic characters using DWUSXNPQKEGCZFJBTLYROHIAVM as key
expected "ciphertext: Rq...", not "ciphertext: Rq..."
:( does not encrypt non-alphabetical characters using DWUSXNPQKEGCZFJBTLYROHIAVM as key
expected "ciphertext: Yq...", not "ciphertext: Yq..."
this is my code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cs50.h>
int main(int argc, string argv[])
{
int f;
int corrector = 0;
if (argc != 2)
{
printf("Usage: ./substitution key");
return 1;
}
string key = argv[1];
string x;
x = get_string("plaintext: ");
int n = strlen(x);
for (int j = 0; j < 26; j++)
{
if (key[j] > 96 && key[j] < 123)
{
key[j] = key[j] - 32;
}
else
{
continue;
}
}
// printf("%s",key);
for (int i = 0; i < n; i++)
{
if (x[i] > 96 && x[i] < 123)
{
x[i] = x[i] - 32;
corrector++;
}
else if ((x[i] < 65 && x[i] > 57) || x[i] < 48 || (x[i] > 90 && x[i] < 97) || x[i] > 122 || (x[i] > 47 && x[i] < 58))
{
// printf("%c",x[i]);
continue;
}
f = x[i] - 64;
x[i] = key[f - 1];
if (corrector == 1)
{
x[i] = x[i] + 32;
corrector = 0;
}
// printf("f=%i i=%i\n",f,i);
}
printf("ciphertext: %s", x);
// printf("%s",x);
return 0;
}
[ad_2]