Atsutanes kleiner Blog
  • home
  • about me
  • downloads
  • unterseiten
  • feed
  • suche

Tags

archlinux blog empfehlung english event frei hinweis howto netzkultur opensource politik projekte psp rl server software systeme unterhaltung vl

Blogroll

  • af-music
  • AVGP
  • ax86
  • BadBoy_
  • botnetz.com
  • Chaosblog
  • darkerradio
  • Ein Mädchen erobert Linux Mint
  • F.A.L.K.
  • Hanshiro
  • holycrap
  • js Blog
  • Kabarakh
  • Keepaway
  • last.fm
  • latino_heat
  • NoName e.V.
  • Planet Archlinux
  • Planet NoName e.V.
  • Planet Pytal
  • Pytalhost-Suche
  • RadioRock
  • somesay
  • Timothy
  • wemaflo
  • wonder's corner
  • Xography
  • XTaran

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;
}

Tags: unterhaltung

Trackback: http://atsutane.freethoughts.de/90/2rot13-meine-implementierung/trackback  :: 0 Kommentare

Kommentare:

keine Kommentare vorhanden

Hinterlasse selbst einen Kommentar:

Was ist die Lösung von sechs minus zwei?

Mit * markierte Felder müssen angegeben werden

devbird v0.4.2 :: Design: AkB :: Impressum :: Login