Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions neutral_example_implentation/opaygo_decoder/opaygo_decoder.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "opaygo_decoder.h"

#define CHECK_BIT(variable, position) ((variable) & (1<<(position)))
#define CHECK_BIT(variable, position) (((variable) >> (position)) & 1)
#define SET_BIT(variable,position,value) (variable & ~(1<<position)) | (value<<position)


Expand All @@ -18,14 +18,14 @@ bool IsInUsedCounts(int Count, uint16_t MaxCount, uint16_t UsedCounts) {
bool IsCountValid(int Count, uint16_t MaxCount, int Value, uint16_t UsedCounts) {
if(Value == COUNTER_SYNC_VALUE) {
// We don't need to check if it's below the max as those tokens aren't tried anyway
if (Count > MaxCount - MAX_TOKEN_JUMP) {
if (Count >= MaxCount - MAX_UNUSED_OLDER_TOKENS_COUNTER_SYNC) {
return true;
}
} else if (Count > MaxCount) {
return true;
} else if(MAX_UNUSED_OLDER_TOKENS > 0 && Count != 0) {
// We check that the count is in the range for unused older token or above
if (Count > MaxCount - MAX_UNUSED_OLDER_TOKENS) {
if (Count >= MaxCount - MAX_UNUSED_OLDER_TOKENS) {
// If it is, we check that its ADD_CREDIT and that this count was not used
if (Count % 2 == 0 && !IsInUsedCounts(Count, MaxCount, UsedCounts)) {
return true;
Expand All @@ -52,7 +52,7 @@ void MarkCountAsUsed(int Count, uint16_t *MaxCount, uint16_t *UsedCounts, int Va
NewUsedCount = SET_BIT(NewUsedCount, (RelativeCount-1), 1);
}
// We move all of the tokens marked as used to their new position relative to the new max count
for(int i=RelativeCount+1; i < MAX_UNUSED_OLDER_TOKENS - RelativeCount; i++) {
for(uint16_t i=RelativeCount; i < MAX_UNUSED_OLDER_TOKENS; i++) {
NewUsedCount = SET_BIT(NewUsedCount, i, CHECK_BIT(*UsedCounts, i-RelativeCount));
}
*UsedCounts = NewUsedCount;
Expand All @@ -77,7 +77,6 @@ TokenData GetDataFromToken(uint64_t InputToken, uint16_t *MaxCount, uint16_t *Us
uint32_t CurrentToken = PutBaseInToken(StartingCode, TokenBase);
uint32_t MaskedToken;
int MaxCountTry;
int MinCountTry;
int Value = DecodeBase(StartingCodeBase, TokenBase);
TokenData output;
bool ValidOlderToken = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define MAX_TOKEN_JUMP 64 // This is a jump in count so up to twice as large as the number of tokens of the same type
#define MAX_TOKEN_JUMP_COUNTER_SYNC 100 // This is a jump in count so up to twice as large as the number of tokens
#define MAX_UNUSED_OLDER_TOKENS 16 // Maximum of 16 (8 tokens of the same type)
#define MAX_UNUSED_OLDER_TOKENS_COUNTER_SYNC 30 // Maximum of 30 counts older is allowed for counter sync

struct TokenDataStruct {
int Value;
Expand Down