From 39b01289671940648914f710708c19334da23c5b Mon Sep 17 00:00:00 2001 From: re-fox <57954766+re-fox@users.noreply.github.com> Date: Mon, 10 Aug 2020 12:13:39 -0400 Subject: [PATCH] Add files via upload --- ...using-luhn-algorithm-with-lookup-table.yml | 68 +++++++++++++++++++ ...ng-luhn-algorithm-with-no-lookup-table.yml | 67 ++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 lib/validate-credit-card-number-using-luhn-algorithm-with-lookup-table.yml create mode 100644 lib/validate-credit-card-number-using-luhn-algorithm-with-no-lookup-table.yml diff --git a/lib/validate-credit-card-number-using-luhn-algorithm-with-lookup-table.yml b/lib/validate-credit-card-number-using-luhn-algorithm-with-lookup-table.yml new file mode 100644 index 00000000..9e97a5c6 --- /dev/null +++ b/lib/validate-credit-card-number-using-luhn-algorithm-with-lookup-table.yml @@ -0,0 +1,68 @@ +rule: + meta: + name: validate credit card number using luhn algorithm with lookup table + lib: true + author: "@_re_fox" + scope: function + examples: + - 1d8fd13c890060464019c0f07b928b1a:0x401920 + - 60abaef3fda131ffa20df480cb3f8029:0x4048e0 + features: + - and: + - not: + - characteristic: nzxor + - characteristic: loop + description: Iterate over CC digits + - basic block: + - or: + - 8 or more: + - number: 0x0 + - number: 0x2 + - number: 0x4 + - number: 0x6 + - number: 0x8 + - number: 0x1 + - number: 0x3 + - number: 0x5 + - number: 0x7 + - number: 0x9 + description: Digital root lookup table + - 8 or more: + - number: 0x0 + - number: 0x1 + - number: 0x2 + - number: 0x3 + - number: 0x4 + - number: 0xfffffffc + - number: 0xfffffffd + - number: 0xfffffffe + - number: 0xffffffff + description: Digital root lookup table via neg numbers + - basic block: + - or: + - and: + - number: 0x30 + - mnemonic: sub + description: Conversion of chr to int (SUB 0x30) + - and: + - mnemonic: lea + - offset: -0x30 + description: Conversion of chr to int (LEA REG,[REG+ -0x30]) + - basic block: + - or: + - and: + - mnemonic: idiv + - mnemonic: cdq + - number: 0xa + - optional : + - mnemonic: neg + description: Final section returning checkum % 10 + - and: + - mnemonic: shr + - mnemonic: imul + - number: 0x66666667 + - number: 0x1f + - number: 0x2 + - optional : + - mnemonic: neg + description: Compiler optimized returning checkum % 10 diff --git a/lib/validate-credit-card-number-using-luhn-algorithm-with-no-lookup-table.yml b/lib/validate-credit-card-number-using-luhn-algorithm-with-no-lookup-table.yml new file mode 100644 index 00000000..8bfc6945 --- /dev/null +++ b/lib/validate-credit-card-number-using-luhn-algorithm-with-no-lookup-table.yml @@ -0,0 +1,67 @@ +rule: + meta: + name: validate credit card number using luhn algorithm with no lookup table + lib: true + author: "@_re_fox" + scope: function + examples: + - 6fcc13563aad936c7d0f3165351cb453:0x4026C0 + features: + - and: + - not: + - characteristic: nzxor + - characteristic: loop + description: Iterate over CC digits + - or: + - basic block: + - and: + - or: + - and: + - mnemonic: add + - and: + - mnemonic: shl + - number: 0x1 + - mnemonic: cmp + - number: 0x9 + description: Digital Root check number*2 < 0x9 + - and: + - basic block: + - and: + - mnemonic: cmp + - number: 0x9 + description: Compare number to 0x9 for Digital Root + - basic block: + - or: + - mnemonic: add + - and: + - mnemonic: shl + - number: 0x1 + description: 2*Number for Digital Root + - basic block: + - or: + - and: + - number: 0x30 + - mnemonic: sub + description: Conversion of chr to int (SUB 0x30) + - and: + - mnemonic: lea + - offset: -0x30 + description: Conversion of chr to int (LEA REG,[REG+ -0x30]) + - basic block: + - or: + - and: + - mnemonic: idiv + - mnemonic: cdq + - number: 0xa + - optional : + - mnemonic: neg + description: Final section returning checkum % 10 + - and: + - mnemonic: shr + - mnemonic: imul + - number: 0x66666667 + - number: 0x1f + - number: 0x2 + - optional : + - mnemonic: neg + description: Compiler optimized returning checkum % 10