Back in February 2016 I created a C# program to test my bit-orientated implementation of SHA-3 using the algorithms in NIST FIPS 202. Today I finished my C implementation, and I created a Win32 64-bit test application. Reference: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf
See Algorithm 10 of FIPS 202:
Enter a hex string
a32e
Enter n
14
H = 10 3 2 14
S = 1 1 0 0 0 1 0 1 0 1 1 1 0 1
D:\FIPS202Algorithm10\x64\Release\FIPS202Algorithm10.exe (process 38932) exited with code 0 (0x0).
Press any key to close this window . . .
// FIPS202Algorithm10.c
// James Pate Williams, Jr.
// Copyright Sunday, February
// 22, 2026 See FIPS 202
// Algorithm 10
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char gHexStr[2048];
int gBinaryStr[8];
int gH[2048], gh[1024];
int gT[8 * 1024 + 7];
int gTruncN[1024];
int gS[1024];
static void ToBinary(int hex)
{
int count = 0;
while (hex > 0)
{
gBinaryStr[count++] = hex & 1;
hex >>= 1;
}
for (int i = count; i < 8; i++)
gBinaryStr[i] = 0;
}
static void Trunc(int X[], int n)
{
for (int i = 0; i < n; i++)
gTruncN[i] = X[i];
}
static void Algorithm10(int m, int n)
{
for (int i = 0; i < m; i++)
{
gh[i] = 16 * gH[2 * i] + gH[2 * i + 1];
}
for (int i = 0; i < m; i++)
{
ToBinary(gh[i]);
for (int j = 0; j < 8; j++)
gT[8 * i + j] = gBinaryStr[j];
}
Trunc(gT, n);
for (int i = 0; i < n; i++)
gS[i] = gTruncN[i];
}
static void HexToBinary(int m, int n)
{
int m2 = m + m;
printf_s("H = ");
for (int i = 0; i < m2; i++)
{
int digit = 0;
if (gHexStr[i] >= '0' && gHexStr[i] <= '9')
digit = gHexStr[i] - '0';
else if (gHexStr[i] >= 'a' && gHexStr[i] <= 'f')
digit = gHexStr[i] - 'a' + 10;
else if (gHexStr[i] >= 'A' && gHexStr[i] <= 'F')
digit = gHexStr[i] - 'A' + 10;
gH[i] = digit;
printf_s("% d ", gH[i]);
}
printf_s("\r\n");
Algorithm10(m, n);
}
int main()
{
int n = 0;
printf_s("Enter a hex string\r\n");
scanf_s("%s", gHexStr, 128);
printf_s("Enter n\r\n");
scanf_s("%d", &n);
int m = (int)strlen(gHexStr);
HexToBinary(m / 2, n);
printf_s("S = ");
for (int i = 0; i < n; i++)
printf_s("%d ", gS[i]);
printf_s("\r\n");
return 0;
}