Skip to content

Instantly share code, notes, and snippets.

@arielmoraes
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arielmoraes/7cc61811510ab368d9b2 to your computer and use it in GitHub Desktop.
Save arielmoraes/7cc61811510ab368d9b2 to your computer and use it in GitHub Desktop.
Desafio001 do Ciência da Computação depressão - Cifra de César
// Ariel Moraes
// https://www.linkedin.com/in/arielmoraes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int mathmod(int a, int b) {
return (abs(a * b) + a) % b;
}
int main(int count, char* args[])
{
char texto[] = "Me encontre na Av. Olimpos em frente ao teatro as 19:00!";
const int shiftsize = 3;
for (int i = 0; i < strlen(texto); i++) {
texto[i] = mathmod(texto[i] + shiftsize - 32, 94) + 32;
}
FILE *f = fopen("resultado.txt", "w");
if (f == NULL)
{
printf("Erro ao criar arquivo\n");
return 1;
}
fprintf(f, "%s\n", texto);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment