2ROT13 - Meine Implementierung
Atsutane, 06.02.2009 - 19:03
BadBoy_ schlug mir vorhin vor, doch eine 2ROT13-Implementierung vorzunehmen und naja, da ich hier ja sowieso mal eine Beispiel-Implementierung des altgedienten ROT13 für Programmierneulinge veröffentlicht habe, habe ich diese eben kurzerhand zu einer 2ROT13-Implementierung umgebaut. Ich muss jedoch sagen, dass das Perlskript, am Ende des Papers, wesentlich eleganter ist.
2rot13.h
#include <stdio.h>
#include <stdlib.h>
#define TABLE_UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLM"
#define TABLE_LOWER "abcdefghijklmnopqrstuvwxyzabcdefghijklm"
void rot13(char *);
char rot13_char(char);
2rot13.c
#include <stdio.h>
#include <stdlib.h>
#include "rot13.h"
void rot13(char *text) {
int i=0, c=0;
for (c=0; c<2; c++) { /* both rounds */
while (text[i] != 0) {
text[i] = rot13_char(text[i]);
i++;
}
i = 0; /* reset i */
}
}
char rot13_char(char c) {
int i = 0;
char table[] = TABLE_LOWER, table2[] = TABLE_UPPER;
while (table[i] != 0) {
if (c == table[i])
return table[i+13];
else if (c == table2[i])
return table2[i+13];
i++;
}
return c;
}


Kommentare:
keine Kommentare vorhanden
Hinterlasse selbst einen Kommentar: