Blog Entry (c) Sunday, February 22, 2026, by James Pate Williams, Jr. A Little Test C Program Source Code and Results

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;
}

Unknown's avatar

Author: jamespatewilliamsjr

My whole legal name is James Pate Williams, Jr. I was born in LaGrange, Georgia approximately 70 years ago. I barely graduated from LaGrange High School with low marks in June 1971. Later in June 1979, I graduated from LaGrange College with a Bachelor of Arts in Chemistry with a little over a 3 out 4 Grade Point Average (GPA). In the Spring Quarter of 1978, I taught myself how to program a Texas Instruments desktop programmable calculator and in the Summer Quarter of 1978 I taught myself Dayton BASIC (Beginner's All-purpose Symbolic Instruction Code) on LaGrange College's Data General Eclipse minicomputer. I took courses in BASIC in the Fall Quarter of 1978 and FORTRAN IV (Formula Translator IV) in the Winter Quarter of 1979. Professor Kenneth Cooper, a genius poly-scientist taught me a course in the Intel 8085 microprocessor architecture and assembly and machine language. We would hand assemble our programs and insert the resulting machine code into our crude wooden box computer which was designed and built by Professor Cooper. From 1990 to 1994 I earned a Bachelor of Science in Computer Science from LaGrange College. I had a 4 out of 4 GPA in the period 1990 to 1994. I took courses in C, COBOL, and Pascal during my BS work. After graduating from LaGrange College a second time in May 1994, I taught myself C++. In December 1995, I started using the Internet and taught myself client-server programming. I created a website in 1997 which had C and C# implementations of algorithms from the "Handbook of Applied Cryptography" by Alfred J. Menezes, et. al., and some other cryptography and number theory textbooks and treatises.

Leave a comment