You are here:   ArielOrtiz.com > Software Design and Architecture > Pipes and Filters Architectural Pattern

Pipes and Filters Architectural Pattern

General Overview

Pipes and filters example.

Reference: Wikipedia

Exercise

ROT13 ("rotate by 13 places", sometimes hyphenated ROT-13) is a simple Caesar cipher used in online forums as a means of hiding spoilers, puzzle solutions, and offensive materials from the casual glance.

Applying ROT13 to a piece of text merely requires examining its alphabetic characters and replacing each one by the letter 13 places further along in the alphabet, wrapping back to the beginning if necessary.[2] A becomes N, B becomes O, and so on up to M, which becomes Z, then the sequence reverses: N becomes A, O becomes B, and so on to Z, which becomes M. Only those letters which occur in the English alphabet are affected; numbers, symbols, whitespace, and all other characters are left unchanged. A second application of ROT13 restores the original text.

A Rot13 example.

Write a complete C# program that implement the ROT13 algorithm as a filter. This means that the input should be read from the standard input and the output should be written to the standard output. You should be able to run your program as follows from a Unix command line (bold text is the user input):

$ mono Rot13.exe
hello world
uryyb jbeyq
^D
$ cat bohemian.txt
Too late, my time has come
Sends shivers down my spine, body's aching all the time
Goodbye, ev'rybody, I've got to go
Gotta leave you all behind and face the truth
Mama, ooh, I don't want to die
I sometimes wish I'd never been born at all
$ cat bohemian.txt | mono Rot13.exe
Gbb yngr, zl gvzr unf pbzr
Fraqf fuviref qbja zl fcvar, obql'f npuvat nyy gur gvzr
Tbbqolr, ri'elobql, V'ir tbg gb tb
Tbggn yrnir lbh nyy oruvaq naq snpr gur gehgu
Znzn, bbu, V qba'g jnag gb qvr
V fbzrgvzrf jvfu V'q arire orra obea ng nyy
$ cat bohemian.txt | mono Rot13.exe | mono Rot13.exe
Too late, my time has come
Sends shivers down my spine, body's aching all the time
Goodbye, ev'rybody, I've got to go
Gotta leave you all behind and face the truth
Mama, ooh, I don't want to die
I sometimes wish I'd never been born at all
$ cat bohemian.txt | mono Rot13.exe | wc
       5 47 238
© 1996-2009 by Ariel Ortiz (ariel.ortiz@itesm.mx)
Made with Django | Licensed under Creative Commons | Valid XHTML | Valid CSS