static int Main(string[] args) { if (args.Length < 1) { Console.WriteLine(PuzzleFileFns.StandardOneParamRequiredErrorMessage); return(1); } var allLines = File.ReadAllLines(args[0]); int payloadStartLine = PuzzleFileFns.GetLinePayloadStartsAt(allLines); var payload = PuzzleFileFns.GetPayloadAsOneLongString(allLines, payloadStartLine); Debug.Assert(payload.StartsWith(@"<~0/)?#c'P?")); Debug.Assert(payload.EndsWith(@"ZOG^Hi`#W@:,!~>")); Debug.Assert(payload.Contains("\n") == false); Debug.Assert(BitwiseFns.FlipEverySecondBit(180) == 225); Debug.Assert(BitwiseFns.RotateByteRight(225) == 240); Func <byte, byte> bytePostProcess = (inByte) => BitwiseFns.RotateByteRight(BitwiseFns.FlipEverySecondBit(inByte)); Debug.Assert(bytePostProcess(180) == 240); var payloadSpan = Ascii85Fns.DecodeAsSpan(payload, 2); var transformedBytes = payloadSpan.ToArray().Select(bytePostProcess).ToArray(); Console.Write(Encoding.ASCII.GetString(transformedBytes)); return(0); }
/// <summary> /// True if the byte has an even amount of bits and the parity bit (LSB) is zero, /// Or the byte has an odd amount of bits and the parity bit is one. /// </summary> public static bool OneBitParityCheck(byte rawByte) { var parityBit = rawByte & 1; var dataBits = (byte)(rawByte & 254); // clears lsb var bitCount = BitwiseFns.GetBitCount(dataBits); return(parityBit == 0 ? bitCount % 2 == 0 : bitCount % 2 == 1); }