Showing posts with label Snippet. Show all posts
Showing posts with label Snippet. Show all posts

Wednesday, January 30, 2008

Snippet: Rijndael Encrypt (and Decrypt)

Here is a pretty easy and useful little snippet to encrypt and decrypt in Rijndael (AES). Nothing fancy, but here it is nonetheless. Oh, and it uses your logged in Windows account name as the key, so you may want to change that to be your company's domain, an MD5, your pet's mother's favorite teacher's high-school sweetheart's maiden name, etc... ;)

Download: Rijndael Encrypt and Decrypt (C#)

Sample Clear:
blah

Sample Encrypted: (with "KEY")
wFf0sBZwld46DOV3Adu3gg==

Sunday, January 20, 2008

Snippet: Lipsum

I needed some Lorem Ipsum for a design that I'm working on. So I hit lipsum.com (as always), and it hit me; why in the world couldn't I turn the lipsum process into a snippet? So here it is. It takes your input and generates replacement words (matching length, and capitalization) extracted from lipsum.com's official output (no injection). Now, they say that there are over 200 words in their dictionary, but I generated 100 paragraphs and only ended up with 186 distinct. Oh well. 186 is still pretty good looking. Have fun!

Click here to download the snippet: Lipsum

Sample Input:
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.

Sample Output:
Praesent et natoque libero, Curae Magna id dis aenean montes erat. In hac velit ad a morbi ac convallis Proin vestibulum nibh 45 ID, tempor ut quam 2000 fusce hac.

Monday, January 7, 2008

Snippet: Compiler

Here's a little snippet (from a friend; thanks again, man!) that will allow you, out of the box, to compile and execute C# code from your SOS input. The results of that code are returned as your response. I'm sure all of the C# coders out there can appreciate this one. One (pretty big) added bonus is the fact that this snippet compiler is not bound to C#. It's not even bound to .NET! Within the configuration file, there are settings that will allow you to specify your own compiler, switches, and base code.

Click here to download the snippet: Compiler

Sample Input:
String text = "Hello World!";
foreach(Char c in text)
{
   String format = "[{0}:{1}] ";
   String character = c.ToString();
   String ascii = ((Int32)c).ToString();
   Console.Write(format, character, ascii.PadLeft(3, '0'));
}

Sample Output:
[H:072] [e:101] [l:108] [l:108] [o:111] [ :032] [W:087] [o:111] [r:114] [l:108] [d:100] [!:033]

Thursday, December 27, 2007

Snippet: ROT-13

ROT-13 is a very simple variation of the Caesar Cipher in which each character is rotated thirteen positions along the Roman alphabet. The purpose of this simplistic cipher is typically to "obstruct" material from view; not necessarily to conceal it. The significance of the thirteen (over Caesar's three) is to allow the cipher to be used as a "toggle" instead of with separate encoding and decoding routines. Since the Roman alphabet has twenty-six letters, rotating a letter thirteen positions will give you its exact inverse; rotating again will give you the original.

Click here to download the snippet: ROT-13

Sample Input:
I'm ROT-13, baby!

Sample Output:
V'z EBG-13, onol!

Snippet: Die Roll

This snippet replaces instances of #d# in a text block with random numbers generated similarly to table-top gaming dice rolls. The random numbers are generated the same way that a die would be rolled in this situation (e.g. "3d6" equates to "roll random 1 to 6 three times; add all three rolls").

Click here to download the snippet: Die Roll

Sample Input:
I have a +1d3 Ring of Codefu, but I may be inclined to part with it for say... 3d20 gold? Hmmm...

Sample Output:
I have a +3 Ring of Codefu, but I may be inclined to part with it for say... 13 gold? Hmmm...

Snippet: HTML Encode

This snippet will ensure that text will store inside "markup" languages (i.e. HTML and XML). Nothing elegant... but highly useful. ;)

Click here to download the snippet: HTML Encode

Sample Input:
<Sample>Some common text & such. Lance really likes using the · symbol in S·O·S, doesn't he?</Sample>

Sample Output:
&lt;Sample&gt;Some common text &amp; such. Lance really likes using the &#183; symbol in S&#183;O&#183;S, doesn't he?&lt;/Sample&gt;

Snippet: Line Number

This snippet will prefix text line with their respective line numbers.
Handy little diagnostic snippet, it is. It supports configuration to change the line-numbers' surrounding characters.

Click here to download the snippet: Line Number

Sample Input:
* Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
* Donec posuere nulla eu eros.
* Mauris fringilla fermentum lorem.
* Morbi eget orci pulvinar nunc sodales malesuada.
* Integer at est at dui dapibus ultrices.

Sample Output:
(1) * Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
(2) * Donec posuere nulla eu eros.
(3) * Mauris fringilla fermentum lorem.
(4) * Morbi eget orci pulvinar nunc sodales malesuada.
(5) * Integer at est at dui dapibus ultrices.