×
Log in
Twitter
Gmail
Facebook
.NET Fiddle
and
.NET Academy
shared account
Remember me
Log in
Sign up
or
Reset password
Search Tutorials
Log in
Sign up
About
Twitter
.NET Fiddle
Support
Contact Us
Symmetric Cryptography
Exercise: Using 16 bits blocks
< Previous
Next >
Please update this code to use 16 bits blocks.
using System; using System.Text; using System.Linq; public class Program { public const int BLOCK_SIZE = 4; public static void Main() { var text = "Symmetric algorithms are pretty fast"; var result = GetBlocks(text); var output = String.Join(" ", result); Console.Write(output); } public static uint[] GetBlocks(string text) { var bytes = Encoding.ASCII.GetBytes(text); var blocksCount = (int)Math.Ceiling(bytes.Count() / (double)BLOCK_SIZE); var result = new uint[blocksCount]; for (int i = 0; i < blocksCount; i++) { result[i] = ToUInt32(bytes.Skip(i * BLOCK_SIZE).Take(BLOCK_SIZE).ToArray()); } return result; } public static UInt32 ToUInt32(byte[] bytes) { UInt32 result = 0; for (int i = 0; i < 4; i++) { result += (UInt32) Math.Pow(256, 3 - i)*bytes[i]; } return result; } }
Reset
Verify
Page 4 of 11
< Previous
Next >
Loading packages and dependencies