From 4062460863c580151d020fa32e90e3fd18fe985f Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 31 May 2023 18:55:11 -0400 Subject: [PATCH] Remove unused Verhoeff code (#26977) --- src/lib/support/BUILD.gn | 3 - src/lib/support/verhoeff/Verhoeff.h | 113 ----------------- src/lib/support/verhoeff/Verhoeff16.cpp | 123 ------------------- src/lib/support/verhoeff/Verhoeff32.cpp | 151 ----------------------- src/lib/support/verhoeff/Verhoeff36.cpp | 157 ------------------------ 5 files changed, 547 deletions(-) delete mode 100644 src/lib/support/verhoeff/Verhoeff16.cpp delete mode 100644 src/lib/support/verhoeff/Verhoeff32.cpp delete mode 100644 src/lib/support/verhoeff/Verhoeff36.cpp diff --git a/src/lib/support/BUILD.gn b/src/lib/support/BUILD.gn index c38c52a2ed21d6..3323d8c9f33e67 100644 --- a/src/lib/support/BUILD.gn +++ b/src/lib/support/BUILD.gn @@ -144,9 +144,6 @@ static_library("support") { "verhoeff/Verhoeff.cpp", "verhoeff/Verhoeff.h", "verhoeff/Verhoeff10.cpp", - "verhoeff/Verhoeff16.cpp", - "verhoeff/Verhoeff32.cpp", - "verhoeff/Verhoeff36.cpp", ] if (current_os == "android" || matter_enable_java_compilation) { diff --git a/src/lib/support/verhoeff/Verhoeff.h b/src/lib/support/verhoeff/Verhoeff.h index 94beafe556e481..eca266e3ff3cd4 100644 --- a/src/lib/support/verhoeff/Verhoeff.h +++ b/src/lib/support/verhoeff/Verhoeff.h @@ -70,119 +70,6 @@ class DLL_EXPORT Verhoeff10 static const uint8_t sPermTable[]; }; -// Verhoeff16 -- Implements Verhoeff's check-digit algorithm for base-16 (hex) strings. -// -class DLL_EXPORT Verhoeff16 -{ - friend class VerhoeffTest; - -public: - enum - { - Base = 16, - PolygonSize = 8 - }; - - // Compute a check character for a given string. - static char ComputeCheckChar(const char * str); - static char ComputeCheckChar(const char * str, size_t strLen); - - // Verify a check character against a given string. - static bool ValidateCheckChar(char checkChar, const char * str); - static bool ValidateCheckChar(char checkChar, const char * str, size_t strLen); - - // Verify a check character at the end of a given string. - static bool ValidateCheckChar(const char * str); - static bool ValidateCheckChar(const char * str, size_t strLen); - - // Convert between a character and its corresponding value. - static int CharToVal(char ch); - static char ValToChar(int val); - -private: - Verhoeff16() = delete; - ~Verhoeff16() = delete; - - static const uint8_t sMultiplyTable[]; - static const uint8_t sPermTable[]; -}; - -// Verhoeff32 -- Implements Verhoeff's check-digit algorithm for base-32 strings. -// -// Character Set (any case): 0-9, A-H, J-N, P, R-Y (excludes I, O, Q and Z). -// -class DLL_EXPORT Verhoeff32 -{ - friend class VerhoeffTest; - -public: - enum - { - Base = 32, - PolygonSize = 16 - }; - - // Compute a check character for a given string. - static char ComputeCheckChar(const char * str); - static char ComputeCheckChar(const char * str, size_t strLen); - - // Verify a check character against a given string. - static bool ValidateCheckChar(char checkChar, const char * str); - static bool ValidateCheckChar(char checkChar, const char * str, size_t strLen); - - // Verify a check character at the end of a given string. - static bool ValidateCheckChar(const char * str); - static bool ValidateCheckChar(const char * str, size_t strLen); - - // Convert between a character and its corresponding value. - static int CharToVal(char ch); - static char ValToChar(int val); - -private: - Verhoeff32() = delete; - ~Verhoeff32() = delete; - - static const uint8_t sMultiplyTable[]; - static const uint8_t sPermTable[]; - static const int8_t sCharToValTable[]; - static const char sValToCharTable[]; -}; - -// Verhoeff36 -- Implements Verhoeff's check-digit algorithm for base-36 strings. -// -// Character Set (any case) : 0-9, A-Z. -// -class DLL_EXPORT Verhoeff36 -{ - friend class VerhoeffTest; - -public: - enum - { - Base = 36, - PolygonSize = 18 - }; - - static char ComputeCheckChar(const char * str); - static char ComputeCheckChar(const char * str, size_t strLen); - static bool ValidateCheckChar(char checkChar, const char * str); - static bool ValidateCheckChar(char checkChar, const char * str, size_t strLen); - static bool ValidateCheckChar(const char * str); - static bool ValidateCheckChar(const char * str, size_t strLen); - - static int CharToVal(char ch); - static char ValToChar(int val); - -private: - Verhoeff36() = delete; - ~Verhoeff36() = delete; - - static const uint8_t sMultiplyTable[]; - static const uint8_t sPermTable[]; - static const int8_t sCharToValTable[]; - static const char sValToCharTable[]; -}; - // Verhoeff -- Implements core functions for Verhoeff's algorithm. // class Verhoeff diff --git a/src/lib/support/verhoeff/Verhoeff16.cpp b/src/lib/support/verhoeff/Verhoeff16.cpp deleted file mode 100644 index 849a89f628f685..00000000000000 --- a/src/lib/support/verhoeff/Verhoeff16.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2013-2017 Nest Labs, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * This file implements an object for Verhoeff's check-digit - * algorithm for base-16 strings. - * - */ -#include "Verhoeff.h" - -#include -#include - -#ifndef VERHOEFF16_NO_MULTIPLY_TABLE - -const uint8_t Verhoeff16::sMultiplyTable[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 0, 9, 10, 11, 12, 13, 14, 15, 8, - 2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 8, 9, 3, 4, 5, 6, 7, 0, 1, 2, 11, 12, 13, 14, 15, 8, 9, 10, - 4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11, 5, 6, 7, 0, 1, 2, 3, 4, 13, 14, 15, 8, 9, 10, 11, 12, - 6, 7, 0, 1, 2, 3, 4, 5, 14, 15, 8, 9, 10, 11, 12, 13, 7, 0, 1, 2, 3, 4, 5, 6, 15, 8, 9, 10, 11, 12, 13, 14, - 8, 15, 14, 13, 12, 11, 10, 9, 0, 7, 6, 5, 4, 3, 2, 1, 9, 8, 15, 14, 13, 12, 11, 10, 1, 0, 7, 6, 5, 4, 3, 2, - 10, 9, 8, 15, 14, 13, 12, 11, 2, 1, 0, 7, 6, 5, 4, 3, 11, 10, 9, 8, 15, 14, 13, 12, 3, 2, 1, 0, 7, 6, 5, 4, - 12, 11, 10, 9, 8, 15, 14, 13, 4, 3, 2, 1, 0, 7, 6, 5, 13, 12, 11, 10, 9, 8, 15, 14, 5, 4, 3, 2, 1, 0, 7, 6, - 14, 13, 12, 11, 10, 9, 8, 15, 6, 5, 4, 3, 2, 1, 0, 7, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -}; - -#endif // VERHOEFF16_NO_MULTIPLY_TABLE - -const uint8_t Verhoeff16::sPermTable[] = { 4, 7, 5, 14, 8, 12, 15, 0, 2, 11, 3, 13, 10, 6, 9, 1 }; - -char Verhoeff16::ComputeCheckChar(const char * str) -{ - return ComputeCheckChar(str, strlen(str)); -} - -char Verhoeff16::ComputeCheckChar(const char * str, size_t strLen) -{ - int c = 0; - - for (size_t i = 1; i <= strLen; i++) - { - char ch = str[strLen - i]; - - int val = CharToVal(ch); - if (val < 0) - return 0; // invalid character - - int p = Verhoeff::Permute(val, sPermTable, Base, i); - -#ifdef VERHOEFF16_NO_MULTIPLY_TABLE - c = Verhoeff::DihedralMultiply(c, p, PolygonSize); -#else - c = sMultiplyTable[c * Base + p]; -#endif - } - - c = Verhoeff::DihedralInvert(c, PolygonSize); - - return ValToChar(c); -} - -bool Verhoeff16::ValidateCheckChar(char checkChar, const char * str) -{ - return ValidateCheckChar(checkChar, str, strlen(str)); -} - -bool Verhoeff16::ValidateCheckChar(char checkChar, const char * str, size_t strLen) -{ - return (ComputeCheckChar(str, strLen) == checkChar); -} - -bool Verhoeff16::ValidateCheckChar(const char * str) -{ - return ValidateCheckChar(str, strlen(str)); -} - -bool Verhoeff16::ValidateCheckChar(const char * str, size_t strLen) -{ - if (strLen == 0) - return false; - return ValidateCheckChar(str[strLen - 1], str, strLen - 1); -} - -int Verhoeff16::CharToVal(char ch) -{ - if (ch >= '0' && ch <= '9') - return ch - '0'; - - if (ch >= 'A' && ch <= 'F') - return (ch - 'A') + 10; - - if (ch >= 'a' && ch <= 'f') - return (ch - 'a') + 10; - - return -1; -} - -char Verhoeff16::ValToChar(int val) -{ - if (val >= 0 && val < 10) - return static_cast('0' + val); - - if (val >= 10 && val < Base) - return static_cast('A' + (val - 10)); - - return 0; -} diff --git a/src/lib/support/verhoeff/Verhoeff32.cpp b/src/lib/support/verhoeff/Verhoeff32.cpp deleted file mode 100644 index dc13a5fa9df955..00000000000000 --- a/src/lib/support/verhoeff/Verhoeff32.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2013-2017 Nest Labs, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * This file implements an object for Verhoeff's check-digit - * algorithm for base-32 strings. - * - */ - -#include "Verhoeff.h" - -#include -#include -#include -#include - -#ifndef VERHOEFF32_NO_MULTIPLY_TABLE - -const uint8_t Verhoeff32::sMultiplyTable[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 16, - 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 16, 17, - 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 16, 17, 18, - 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 16, 17, 18, 19, - 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 16, 17, 18, 19, 20, - 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 16, 17, 18, 19, 20, 21, - 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 23, 24, 25, 26, 27, 28, 29, 30, 31, 16, 17, 18, 19, 20, 21, 22, - 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 24, 25, 26, 27, 28, 29, 30, 31, 16, 17, 18, 19, 20, 21, 22, 23, - 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 25, 26, 27, 28, 29, 30, 31, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 26, 27, 28, 29, 30, 31, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, - 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 27, 28, 29, 30, 31, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, - 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 28, 29, 30, 31, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, - 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 29, 30, 31, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, - 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 30, 31, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 31, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - 16, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, - 17, 16, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, - 18, 17, 16, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, - 19, 18, 17, 16, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, - 20, 19, 18, 17, 16, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, - 21, 20, 19, 18, 17, 16, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, - 22, 21, 20, 19, 18, 17, 16, 31, 30, 29, 28, 27, 26, 25, 24, 23, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, - 23, 22, 21, 20, 19, 18, 17, 16, 31, 30, 29, 28, 27, 26, 25, 24, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, - 24, 23, 22, 21, 20, 19, 18, 17, 16, 31, 30, 29, 28, 27, 26, 25, 8, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, - 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 31, 30, 29, 28, 27, 26, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, - 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 31, 30, 29, 28, 27, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 31, 30, 29, 28, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, - 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 31, 30, 29, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, - 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 31, 30, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, - 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 31, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 15, - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -}; - -#endif // VERHOEFF32_NO_MULTIPLY_TABLE - -const uint8_t Verhoeff32::sPermTable[] = { - // Detects all single digit and adjacent transposition errors, and 97.076613% of jump transposition errors. - 7, 2, 1, 30, 16, 20, 27, 11, 31, 6, 8, 13, 29, 5, 10, 21, 22, 3, 24, 0, 23, 25, 12, 9, 28, 14, 4, 15, 17, 18, 19, 26, -}; - -const int8_t Verhoeff32::sCharToValTable[] = { - // NOTE: table starts at ASCII 30h - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, 16, 17, - -1, 18, 19, 20, 21, 22, -1, 23, -1, 24, 25, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -1, -1, 10, - 11, 12, 13, 14, 15, 16, 17, -1, 18, 19, 20, 21, 22, -1, 23, -1, 24, 25, 26, 27, 28, 29, 30, 31 -}; - -const char Verhoeff32::sValToCharTable[] = "0123456789ABCDEFGHJKLMNPRSTUVWXY"; - -char Verhoeff32::ComputeCheckChar(const char * str) -{ - return ComputeCheckChar(str, strlen(str)); -} - -char Verhoeff32::ComputeCheckChar(const char * str, size_t strLen) -{ - int c = 0; - - for (size_t i = 1; i <= strLen; i++) - { - char ch = str[strLen - i]; - - int val = CharToVal(ch); - if (val < 0) - return 0; // invalid character - - int p = Verhoeff::Permute(val, sPermTable, Base, i); - -#ifdef VERHOEFF32_NO_MULTIPLY_TABLE - c = Verhoeff::DihedralMultiply(c, p, PolygonSize); -#else - c = sMultiplyTable[c * Base + p]; -#endif - } - - c = Verhoeff::DihedralInvert(c, PolygonSize); - - return ValToChar(c); -} - -bool Verhoeff32::ValidateCheckChar(char checkChar, const char * str) -{ - return ValidateCheckChar(checkChar, str, strlen(str)); -} - -bool Verhoeff32::ValidateCheckChar(char checkChar, const char * str, size_t strLen) -{ - return (ComputeCheckChar(str, strLen) == checkChar); -} - -bool Verhoeff32::ValidateCheckChar(const char * str) -{ - return ValidateCheckChar(str, strlen(str)); -} - -bool Verhoeff32::ValidateCheckChar(const char * str, size_t strLen) -{ - if (strLen == 0) - return false; - return ValidateCheckChar(str[strLen - 1], str, strLen - 1); -} - -int Verhoeff32::CharToVal(char ch) -{ - if (ch >= '0' && ch <= 'y') - return sCharToValTable[static_cast(ch) - '0']; - return -1; -} - -char Verhoeff32::ValToChar(int val) -{ - if (val >= 0 && val < Base) - return sValToCharTable[val]; - return 0; -} diff --git a/src/lib/support/verhoeff/Verhoeff36.cpp b/src/lib/support/verhoeff/Verhoeff36.cpp deleted file mode 100644 index b0131421886fbd..00000000000000 --- a/src/lib/support/verhoeff/Verhoeff36.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2013-2017 Nest Labs, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * This file implements an object for Verhoeff's check-digit - * algorithm for base-36 strings. - * - */ -#include "Verhoeff.h" - -#include -#include -#include -#include - -#ifndef VERHOEFF36_NO_MULTIPLY_TABLE - -const uint8_t Verhoeff36::sMultiplyTable[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, - 29, 30, 31, 32, 33, 34, 35, 18, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 20, 21, 22, 23, 24, 25, - 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 18, 19, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 21, 22, - 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 18, 19, 20, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, - 2, 3, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 18, 19, 20, 21, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 0, 1, 2, 3, 4, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 18, 19, 20, 21, 22, 6, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 18, 19, 20, 21, 22, 23, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 18, 19, 20, 21, 22, 23, 24, - 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 18, 19, 20, 21, - 22, 23, 24, 25, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 27, 28, 29, 30, 31, 32, 33, 34, 35, 18, - 19, 20, 21, 22, 23, 24, 25, 26, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 28, 29, 30, 31, 32, 33, - 34, 35, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 29, 30, - 31, 32, 33, 34, 35, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 10, 11, 30, 31, 32, 33, 34, 35, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12, 31, 32, 33, 34, 35, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 14, 15, 16, 17, 0, 1, 2, 3, - 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 32, 33, 34, 35, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 15, 16, 17, 0, - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 33, 34, 35, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, - 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 34, 35, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31, 32, 33, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 35, 18, 19, 20, 21, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 31, 32, 33, 34, 18, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 0, 17, 16, 15, 14, 13, - 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 19, 18, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 1, 0, - 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 20, 19, 18, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, - 22, 21, 2, 1, 0, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 21, 20, 19, 18, 35, 34, 33, 32, 31, 30, 29, 28, - 27, 26, 25, 24, 23, 22, 3, 2, 1, 0, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 22, 21, 20, 19, 18, 35, 34, 33, - 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 4, 3, 2, 1, 0, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 23, 22, 21, 20, - 19, 18, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 5, 4, 3, 2, 1, 0, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, - 24, 23, 22, 21, 20, 19, 18, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 6, 5, 4, 3, 2, 1, 0, 17, 16, 15, 14, 13, 12, 11, - 10, 9, 8, 7, 25, 24, 23, 22, 21, 20, 19, 18, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 7, 6, 5, 4, 3, 2, 1, 0, 17, 16, - 15, 14, 13, 12, 11, 10, 9, 8, 26, 25, 24, 23, 22, 21, 20, 19, 18, 35, 34, 33, 32, 31, 30, 29, 28, 27, 8, 7, 6, 5, 4, 3, - 2, 1, 0, 17, 16, 15, 14, 13, 12, 11, 10, 9, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 35, 34, 33, 32, 31, 30, 29, 28, 9, 8, - 7, 6, 5, 4, 3, 2, 1, 0, 17, 16, 15, 14, 13, 12, 11, 10, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 35, 34, 33, 32, 31, - 30, 29, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 17, 16, 15, 14, 13, 12, 11, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, - 35, 34, 33, 32, 31, 30, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 17, 16, 15, 14, 13, 12, 30, 29, 28, 27, 26, 25, 24, 23, - 22, 21, 20, 19, 18, 35, 34, 33, 32, 31, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 17, 16, 15, 14, 13, 31, 30, 29, 28, - 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 35, 34, 33, 32, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 17, 16, 15, 14, - 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 35, 34, 33, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, - 0, 17, 16, 15, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 35, 34, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, - 5, 4, 3, 2, 1, 0, 17, 16, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 35, 16, 15, 14, 13, 12, 11, - 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 17, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, - 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -}; - -#endif // VERHOEFF36_NO_MULTIPLY_TABLE - -const uint8_t Verhoeff36::sPermTable[] = { 29, 0, 32, 11, 35, 20, 7, 27, 2, 4, 19, 28, 30, 1, 5, 12, 3, 9, - 16, 22, 6, 33, 8, 24, 26, 21, 14, 10, 34, 31, 15, 25, 17, 13, 23, 18 }; - -const int8_t Verhoeff36::sCharToValTable[] = { - // NOTE: table starts at ASCII 30h - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, 16, 17, - 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, -1, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 -}; - -const char Verhoeff36::sValToCharTable[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - -char Verhoeff36::ComputeCheckChar(const char * str) -{ - return ComputeCheckChar(str, strlen(str)); -} - -char Verhoeff36::ComputeCheckChar(const char * str, size_t strLen) -{ - int c = 0; - - for (size_t i = 1; i <= strLen; i++) - { - char ch = str[strLen - i]; - - int val = CharToVal(ch); - if (val < 0) - return 0; // invalid character - - int p = Verhoeff::Permute(val, sPermTable, Base, i); - -#ifdef VERHOEFF36_NO_MULTIPLY_TABLE - c = Verhoeff::DihedralMultiply(c, p, PolygonSize); -#else - c = sMultiplyTable[c * Base + p]; -#endif - } - - c = Verhoeff::DihedralInvert(c, PolygonSize); - - return ValToChar(c); -} - -bool Verhoeff36::ValidateCheckChar(char checkChar, const char * str) -{ - return ValidateCheckChar(checkChar, str, strlen(str)); -} - -bool Verhoeff36::ValidateCheckChar(char checkChar, const char * str, size_t strLen) -{ - return (ComputeCheckChar(str, strLen) == checkChar); -} - -bool Verhoeff36::ValidateCheckChar(const char * str) -{ - return ValidateCheckChar(str, strlen(str)); -} - -bool Verhoeff36::ValidateCheckChar(const char * str, size_t strLen) -{ - if (strLen == 0) - return false; - return ValidateCheckChar(str[strLen - 1], str, strLen - 1); -} - -int Verhoeff36::CharToVal(char ch) -{ - if (ch >= '0' && ch <= 'z') - return sCharToValTable[static_cast(ch) - '0']; - return -1; -} - -char Verhoeff36::ValToChar(int val) -{ - if (val >= 0 && val < Base) - return sValToCharTable[val]; - return 0; -}