Browse files

Added a new, smaller and faster algorithm! Added rot47.c - a rot47 en…

…coder
  • Loading branch information...
1 parent c8060c6 commit 0e93a22ebc213ac08970dae804c40691de42b196 @aliclubb committed May 27, 2012
Showing with 44 additions and 40 deletions.
  1. +5 −0 Makefile
  2. +1 −1 README.md
  3. +1 −2 rot-tools/README.md
  4. +8 −14 rot-tools/rot13.c
  5. +14 −23 rot-tools/rot18.c
  6. +15 −0 rot-tools/rot47.c
View
5 Makefile
@@ -7,27 +7,31 @@ all:
ifeq ($(OS), Darwin)
$(CC) $(CFLAGS) -o bin/rot13 rot-tools/rot13.c
$(CC) $(CFLAGS) -o bin/rot18 rot-tools/rot18.c
+ $(CC) $(CFLAGS) -o bin/rot47 rot-tools/rot47.c
$(CC) $(CFLAGS) -o bin/ascii2char ascii-tools/ascii2char.c
$(CC) $(CFLAGS) -o bin/char2ascii ascii-tools/char2ascii.c
$(CC) $(CFLAGS) -o bin/ascii-tools ascii-tools/ascii-tools.c
endif
ifeq ($(OS), Linux)
$(CC) $(CFLAGS) -o bin/rot13 rot-tools/rot13.c
$(CC) $(CFLAGS) -o bin/rot18 rot-tools/rot18.c
+ $(CC) $(CFLAGS) -o bin/rot47 rot-tools/rot47.c
$(CC) $(CFLAGS) -o bin/ascii2char ascii-tools/ascii2char.c
$(CC) $(CFLAGS) -o bin/char2ascii ascii-tools/char2ascii.c
$(CC) $(CFLAGS) -o bin/ascii-tools ascii-tools/ascii-tools.c
endif
ifeq ($(OS), CYGWIN_NT-5.1)
$(CC) $(CFLAGS) -o bin/rot13 rot-tools/rot13.c
$(CC) $(CFLAGS) -o bin/rot18 rot-tools/rot18.c
+ $(CC) $(CFLAGS) -o bin/rot47 rot-tools/rot47.c
$(CC) $(CFLAGS) -o bin/ascii2char ascii-tools/ascii2char.c
$(CC) $(CFLAGS) -o bin/char2ascii ascii-tools/char2ascii.c
$(CC) $(CFLAGS) -o bin/ascii-tools ascii-tools/ascii-tools.c
endif
install:
cp bin/rot13 /usr/local/bin/rot13
cp bin/rot18 /usr/local/bin/rot18
+ cp bin/rot47 /usr/local/bin/rot47
cp bin/ascii2char /usr/local/bin/ascii2char
cp bin/char2ascii /usr/local/bin/char2ascii
cp bin/ascii-tools /usr/local/bin/ascii-tools
@@ -38,6 +42,7 @@ clean:
uninstall:
rm -f /usr/local/bin/rot13
rm -f /usr/local/bin/rot18
+ rm -f /usr/local/bin/rot47
rm -f /usr/local/bin/ascii2char
rm -f /usr/local/bin/char2ascii
rm -f /usr/local/bin/ascii-tools
View
2 README.md
@@ -1,4 +1,4 @@
misc-tools
==========
-This is a collection of miscellaneous tools that I have made over time. No really, they have no use as far as I am concerned! :)
+This is a collection of miscellaneous tools that I have made over time. No really, they have no use as far as I am concerned
View
3 rot-tools/README.md
@@ -1,5 +1,4 @@
rot-tools
==========
- A quick suite of ROT13 and 18 tools which I made during a spare 10 minutes :)
- EDIT: I am experimenting with other languages at the moment, so I am porting some of my programs :)
+ A quick suite of ROT13 and 18 tools which I made during a spare 10 minutes
View
22 rot-tools/rot13.c
@@ -1,21 +1,15 @@
#include <stdio.h>
+#include <ctype.h>
-int main(c, t)
+int main(c)
{
- while((c = getchar()) != 10)
- if((c >= 78 && c < 92) || (c >= 110))
- {
- t = 0;
- for(;(c >= 78 && c < 92) || (c >= 110);--c)
- ++t;
- if(c > 92)
- putchar(96 + t);
+ while((c = getchar()) != EOF)
+ if(isalpha(c))
+ if((c < 78) || (96 < c && c < 110))
+ putchar(c + 13);
else
- putchar(64 + t);
- }
- else if(c != 32)
- putchar(c + 13);
+ putchar(c - 13);
else
- putchar(32);
+ putchar(c);
return 0;
}
View
37 rot-tools/rot18.c
@@ -1,30 +1,21 @@
#include <stdio.h>
+#include <ctype.h>
-int main(c, t)
+int main(c)
{
- while((c = getchar()) != 10)
- if((c >= 78 && c < 92) || (c >= 110))
- {
- t = 0;
- for(;(c >= 78 && c < 92) || (c >= 110);--c)
- ++t;
- if(c > 92)
- putchar(96 + t);
+ while((c = getchar()) != EOF)
+ if(isalpha(c))
+ if((c < 78) || (96 < c && c < 110))
+ putchar(c + 13);
else
- putchar(64 + t);
- }
- else if(c != 32 && c > 60)
- putchar(c + 13);
- else if(c == 32)
- putchar(c);
- else if(c >= 53)
- {
- t = 0;
- for(;c >= 54;--c)
- ++t;
- putchar(48 + t);
- }
+ putchar(c - 13);
else
- putchar(c + 5);
+ if(c < 48)
+ putchar(c);
+ else
+ if((c > 32 && c < 53))
+ putchar(c + 5);
+ else
+ putchar(c - 5);
return 0;
}
View
15 rot-tools/rot47.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+int main ()
+{
+ int c;
+ while ((c = getchar()) != EOF)
+ if(32 < c)
+ if(c < 80)
+ putchar(c + 47);
+ else
+ putchar(c - 47);
+ else
+ putchar(c);
+ return 0;
+}

0 comments on commit 0e93a22

Please sign in to comment.