vigenere.c
#include "vigenere.h"
char char_valid(char c)
{
return c >= charmin && c <= charmax;
}
unsigned short char2short(char c)
{
return c - charmin;
}
char short2char(unsigned short c)
{
return c + charmin;
}
void codageVigenere(const char* src, char* dest, const char* clef, vigenere codage)
{
const int num_chars = charmax - charmin + 1;
const char* k = clef;
for (const char* p = src; *p; p++)
{
*dest++ = char_valid(*p)
? short2char(((short)(char2short(*p) - (2 * codage - 1) * char2short(*k)) % num_chars + num_chars) % num_chars)
: *p;
if (!*++k)
k = clef;
}
*dest = 0;
}
pascal.c
#include <stdio.h>
#include <string.h>
#include "pascal.h"
void afficheTPascal(unsigned char rang)
{
rang++;
int pascal[rang];
memset(pascal, 0, rang * sizeof(int));
pascal[0] = 1;
for (unsigned char i = 1; i < rang; i++)
{
for (unsigned char j = i; j >= 1; j--)
{
printf("%4d ", pascal[j] += pascal[j - 1]);
}
printf("%4d \n", 1);
}
}
ou, pour n'afficher qu'une ligne du triangle
void afficheTPascal(unsigned char rang)
{
rang++;
int pascal[rang];
memset(pascal, 0, rang * sizeof(int));
pascal[0] = 1;
for (unsigned char i = 1; i < rang; i++)
{
for (unsigned char j = i; j >= 1; j--)
{
pascal[j] += pascal[j - 1];
}
}
for (unsigned char i = 0; i < rang; i++)
{
printf("%4d ", pascal[i]);
}
putchar('\n');
}