Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.VisualBasic.Devices;
- using System.Threading.Tasks;
- namespace BinaryBufferSerializer
- {
- public class Program
- {
- static string[] primIdens = { "1", "4", "7", "a", "d", "g", "j", "m", "p", "s", "v", "y", "A", "D", "G", "J", "M", "P", "S", "V", "Y" };
- static string[] secoIdens = { "2", "5", "8", "b", "e", "h", "k", "n", "q", "t", "w", "z", "B", "E", "H", "K", "N", "Q", "T", "W", "Z" };
- static string[] paddingIdens = { "0", "3", "6", "9", "c", "f", "i", "l", "o", "r", "u", "x", "C", "F", "I", "L", "O", "R", "U", "X" };
- public static void Main(string[] args)
- {
- ComputerInfo pcInfo = new ComputerInfo();
- var importantPcData = new
- {
- os = new
- {
- name = pcInfo.OSFullName,
- version = pcInfo.OSVersion,
- platform = pcInfo.OSPlatform,
- },
- memory = new
- {
- total_physical_memory = pcInfo.TotalPhysicalMemory,
- total_virtual_memory = pcInfo.TotalVirtualMemory,
- available_physical_memory = pcInfo.AvailablePhysicalMemory,
- available_virtual_memory = pcInfo.AvailableVirtualMemory
- },
- time = new
- {
- time_now = DateTime.Now.ToString(),
- time_now_epoch = DateTime.Now.ToFileTime().ToString(),
- time_utc = DateTime.Now.ToUniversalTime().ToString(),
- time_utc_epoch = DateTime.Now.ToFileTimeUtc().ToString(),
- },
- framework = new
- {
- framework_version = "net461",
- framework_interop_functional = true,
- framework_json_dep = "netstandard1.1"
- }
- };
- string data = JsonConvert.SerializeObject(importantPcData);
- Console.WriteLine("Serializing " + data);
- string binaryData = SerializeData(data);
- Console.WriteLine(binaryData);
- Console.ReadLine();
- }
- static string SerializeData(string data)
- {
- return SerializeBinaryData(Encoding.UTF8.GetBytes(data));
- }
- static string SerializeBinaryData(byte[] buffer)
- {
- Random random = new Random();
- string _binaryRep = ReadBinaryData(buffer);
- char[] binaryChars = _binaryRep.ToCharArray();
- string serializedData = null;
- for (int charLoc = 0; charLoc < binaryChars.Length; charLoc++)
- {
- BitType bitType = binaryChars[charLoc] == '0'
- ? BitType.Zero : binaryChars[charLoc] == '1'
- ? BitType.One : BitType.Padding;
- switch (bitType)
- {
- case BitType.Zero:
- serializedData += primIdens[random.Next(primIdens.Length - 1)];
- break;
- case BitType.One:
- serializedData += secoIdens[random.Next(secoIdens.Length - 1)];
- break;
- case BitType.Padding:
- serializedData += paddingIdens[random.Next(paddingIdens.Length - 1)];
- break;
- default:
- throw new InvalidOperationException();
- }
- }
- return serializedData;
- }
- static string ReadBinaryData(byte[] buffer)
- {
- string binaryData = null;
- for (int byteLoc = 0; byteLoc < buffer.Length; byteLoc++)
- {
- binaryData += Convert.ToString(buffer[byteLoc], 2).PadLeft(8, '0');
- binaryData += " "; // Add bit/byte padding.
- }
- return binaryData;
- }
- }
- public enum BitType
- {
- Zero = 0,
- One = 1,
- Padding = 3,
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement