V
V
vision-bk2015-09-21 00:24:47
Programming
vision-bk, 2015-09-21 00:24:47

How to convert a string (key) into an array of 8 blocks, where 1 block is 32 bits (C#)?

There is, for example, the key string key = "E2C104F9 E41D7CDE 7FE5E857 060265B4 281CCC85 2E2C929A 47464503 E00CE510". How to convert it programmatically into a key, 256 bits in size, and then divide it into 8 blocks of 32 bits each?
Or how to immediately write this key as an array of 8 blocks of 32 bits?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ar4ebaldello, 2015-09-21
@vision-bk

var key = "E2C104F9 E41D7CDE 7FE5E857 060265B4 281CCC85 2E2C929A 47464503 E00CE510";
var blocks =
    key.Split(' ')
        .Select(
            i => i.Aggregate(0, (current, j) => current * 16 + ((j >= '0' && j <= '9') ? j - '0' : j - 'A')))
        .ToArray();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question