#!/usr/bin/perl
# © 2005 Andrew Keyser
# Last updated: 2006-03-19
# Synopsis:
#   dvenc [format] < file.txt > file.txt.dvenc
#   echo "something" | dvenc [format]
# Purpose:
#   Script to encode and decode Dvorak encoded files.
#   See <http://turbogfx.homelinux.org/dvorak-encoding>.
# Notes:
#   [format] is one of DvQW, DvrQW, DvlQW, QWDv, QWDvr, or QWDvr. To decode,
#   pick the opposite of what you encoded it with.
#   Reads standard input. Outputs on standard output.
#   To make it a higher level of encoding, pipe it through dvenc x times to
#   make it [format]x.
#   Different combinations of Dvr and Dvl can be used to compose very
#   complicated encodings.

use strict;
use warnings;
my $fmt = shift;
my $file;
local $/;
$file = <STDIN>;
close STDIN;

if ( lc $fmt eq 'dvqw') {
	$file =~
tr/
\[\{\]\}'",<\.>pPyYfFgGcCrRlL\/\?=\+oOeEuUiIdDhHtTnNsS\-_;:qQjJkKxXbBwWvVzZ/
\-_=\+qQwWeErRtTyYuUiIoOpP\[\{\]\}sSdDfFgGhHjJkKlL;:'"zZxXcCvVbBnN,<\.>\/\?/;
	
}

elsif ( lc $fmt eq 'qwdv') {
	$file =~
tr/
\-_=\+qQwWeErRtTyYuUiIoOpP\[\{\]\}sSdDfFgGhHjJkKlL;:'"zZxXcCvVbBnN,<\.>\/\?/
\[\{\]\}'",<\.>pPyYfFgGcCrRlL\/\?=\+oOeEuUiIdDhHtTnNsS\-_;:qQjJkKxXbBwWvVzZ/;
}

elsif ( lc $fmt eq 'dvrqw') {
	$file =~
tr/
jJlLmMfFpP\/\?\[\{\]\}5%6\^qQ\.>oOrRsSuUyYbB;:=\+7\&8\*zZaAeEhHtTdDcCkK\-_9\(0\)xX,<iInNwWvVgG'"/
5%6\^7\&8\*9\(0\)\-_=\+qQwWeErRtTyYuUiIoOpP\[\{\]\}aAsSdDfFgGhHjJkKlL;:'"zZxXcCvVbBnNmM,<\.>\/\?/;
}

elsif ( lc $fmt eq 'qwdvr') {
	$file =~
tr/
5%6\^7\&8\*9\(0\)\-_=\+q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