Skip to content

Commit

Permalink
Ajout du codage morse
Browse files Browse the repository at this point in the history
  • Loading branch information
marrez committed Jan 16, 2017
1 parent 2b180fb commit e6e5ae8
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 0 deletions.
Binary file added sprint/Cryptage/crypt
Binary file not shown.
3 changes: 3 additions & 0 deletions sprint/getMorse/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
getMorse: main.c functions.c
gcc -o getMorse main.c functions.c -I.

1 change: 1 addition & 0 deletions sprint/getMorse/Text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A B C
92 changes: 92 additions & 0 deletions sprint/getMorse/functions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include "functions.h"

int ascii2morse(char *s, FILE *outfile){

char *letters[] = {
"1 -1 3 ", // A | a
"3 -1 1 -1 1 -1 1 ", // B | b
"3 -1 1 -1 3 -1 1 ", // C | c
"3 -1 1 -1 1 ", // D | d
"1 ", // E | e
"1 -1 1 -1 3 -1 1 ", // F | f
"3 -1 3 -1 1 ", // G | g
"1 -1 1 -1 1 -1 1 ", // H | h
"1 -1 1 -1 ", // I | i
"1 -1 3 -1 3 -1 3 ", // J | j
"3 -1 1 -1 3 ", // K | k
"1 -1 3 -1 1 -1 1 ", // L | l
"3 -1 3 ", // M | m
"3 -1 1 ", // N | n
"3 -1 3 -1 3 ", // O | o
"1 -1 3 -1 3 -1 1 ", // P | p
"3 -1 3 -1 1 -1 3 ", // Q | q
"1 -1 3 -1 1 ", // R | r
"1 -1 1 -1 1 ", // S | s
"3 ", // T | t
"1 -1 1 -1 3 ", // U | u
"1 -1 1 -1 1 -1 3 ", // V | v
"1 -1 3 -1 3 ", // W | w
"3 -1 1 -1 1 -1 3 ", // X | x
"3 -1 1 -1 3 -1 3 ", // Y | y
"3 -1 3 -1 1 -1 1 " // Z | z
};

char *numbers[] = {
"3 -1 3 -1 3 -1 3 -1 3 ", // 0
"1 -1 3 -1 3 -1 3 -1 3 ", // 1
"1 -1 1 -1 3 -1 3 -1 3 ", // 2
"1 -1 1 -1 1 -1 3 -1 3 ", // 3
"1 -1 1 -1 1 -1 1 -1 3 ", // 4
"1 -1 1 -1 1 -1 1 -1 1 ", // 5
"3 -1 1 -1 1 -1 1 -1 1 ", // 6
"3 -1 3 -1 1 -1 1 -1 1 ", // 7
"3 -1 3 -1 3 -1 1 -1 1 ", // 8
"3 -1 3 -1 3 -1 3 -1 3 ", // 9
};

int i, c;
for (i=0;i<strlen(s);i++){

c = s[i];
if (c != ' '){
// selectionner le caractere
if((c <= 'z') && (c >= 'a'))
fputs(letters[c - 'a'],outfile);

else if((c <= 'Z') && (c >= 'A'))
fputs(letters[c - 'A'],outfile);

else if((c <= '9') && (c >= '0'))
fputs(numbers[c - '0'],outfile);

else if(c == '.')
fputs("1 -1 3 -1 1 -1 3 -1 1 -1 3 ",outfile);

else if(c == ',')
fputs("3 -1 3 -1 1 -1 1 -1 3 -1 3 ",outfile);

else if(c == '?')
fputs("1 -1 1 -1 3 -1 3 -1 1 -1 1 ",outfile);

else if(c == '-')
fputs("3 -1 1 -1 1 -1 1 -1 1 -1 3 ",outfile);

else // caractere non valide
printf("Le caracter %c n'est pas valide \nValeur en ASCII = %d\ni = %d",s[i],s[i],i);

// espace entre elements
if (s[i+2] == '\0')
break;
if (s[i+1] != ' ')
fputs("-3 ",outfile); // entre elements
else{
fputs("-7 ",outfile); // fin d'un mot
i++;
}
}
}

//fclose(f);

return EXIT_SUCCESS;
}
10 changes: 10 additions & 0 deletions sprint/getMorse/functions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifndef FUNCTIONS_H_INCLUDED
#define FUNCTIONS_H_INCLUDED

int ascii2morse(char *s, FILE *outfile);

#endif
Binary file added sprint/getMorse/getMorse
Binary file not shown.
22 changes: 22 additions & 0 deletions sprint/getMorse/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "functions.h"

int main(int argc, char *argv[]){

if(argc < 3){
printf("Utilisation :\n ./main infile outfile\n");
return EXIT_FAILURE;
}

FILE *infile;
char s[100];

// Charger le message
infile = fopen(argv[1],"r");
fgets(s,500,infile);
fclose(infile);

FILE *outfile = fopen(argv[2],"w+");
ascii2morse(s,outfile);

return EXIT_SUCCESS;
}
1 change: 1 addition & 0 deletions sprint/getMorse/morse.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 -1 3 -7 3 -1 1 -1 1 -1 1 -7 3 -1 1 -1 3 -1 1

0 comments on commit e6e5ae8

Please sign in to comment.