From de5650a4375c1102572c8bb7a694e9c0068db29a Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Mon, 10 Oct 2016 10:55:59 +0700 Subject: Update /r/dailyprogrammer challenge #285 [Easy] --- daily/285easy/279easy.md | 130 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 daily/285easy/279easy.md (limited to 'daily/285easy/279easy.md') diff --git a/daily/285easy/279easy.md b/daily/285easy/279easy.md new file mode 100644 index 0000000..8a7adbb --- /dev/null +++ b/daily/285easy/279easy.md @@ -0,0 +1,130 @@ +# [[2016-08-16] Challenge #279 [Easy] Uuencoding](https://www.reddit.com/r/dailyprogrammer/comments/4xy6i1/20160816_challenge_279_easy_uuencoding/) + +You are trapped at uninhabited island only with your laptop. Still you don't +want your significant other to worry about you, so you are going to send a +message in a bottle with your picture or at least a couple of words from you +(sure, you could just write down the words, but that would be less fun). You're +going to use uuencoding for that. + +Uuencoding is a form of binary-to-text encoding, which uses only symbols from +32-95 diapason, which means all symbols used in the encoding are printable. + +## Description of encoding + +A uuencoded file starts with a header line of the form: + + begin + + is the file's Unix file permissions as three octal digits (e.g. 644, +744). For Windows 644 is always used. + + is the file name to be used when recreating the binary data. + + signifies a newline character, used to terminate each line. + +Each data line uses the format: + + + + is a character indicating the number of data bytes which +have been encoded on that line. This is an ASCII character determined by adding +32 to the actual byte count, with the sole exception of a grave accent "`" +(ASCII code 96) signifying zero bytes. All data lines except the last (if the +data was not divisible by 45), have 45 bytes of encoded data (60 characters +after encoding). Therefore, the vast majority of length values is 'M', (32 + 45 += ASCII code 77 or "M"). + + are encoded characters. + +The mechanism of uuencoding repeats the following for every 3 bytes (if there +are less than 3 bytes left, trailing 0 are added): + +1. Start with 3 bytes from the source, 24 bits in total. +2. Split into 4 6-bit groupings, each representing a value in the range 0 to + 63: bits (00-05), (06-11), (12-17) and (18-23). +3. Add 32 to each of the values. With the addition of 32 this means that the + possible results can be between 32 (" " space) and 95 ("_" underline). 96 + ("`" grave accent) as the "special character" is a logical extension of this + range. +4. Output the ASCII equivalent of these numbers. + +For example, we want to encode a word "Cat". ASCII values for C,a,t are +67,97,116, or `010000110110000101110100` in binary. After dividing into four +groups, we get 010000 110110 000101 110100, which is 16,54,5,52 in decimal. +Adding 32 to this values and encoding back in ASCII, the final result is +`0V%T`. + +The file ends with two lines: + + ` + end + +## Formal Inputs & Outputs + +### Input + +a byte array or string. + +### Output + +a string containing uuencoded input. + +## Examples + +Input: Cat + +Output: + + begin 644 cat.txt + #0V%T + ` + end + +Input: + +I feel very strongly about you doing duty. Would you give me a little more +documentation about your reading in French? I am glad you are happy — but I +never believe much in happiness. I never believe in misery either. Those are +things you see on the stage or the screen or the printed pages, they never +really happen to you in life. + +Output: + + begin 644 file.txt + M22!F965L('9E6]U(&1O:6YG(&1U='DN(%=O + M=6QD('EO=2!G:79E(&UE(&$@;&ET=&QE(&UO2!N979E