Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * ordenador_crypt.c - Validador físico baseado em bomba de Arquimedes
- * Inspirado em fluxo natural contínuo com buffer circular
- * Aplicação: validação de chaves com base em ordenação espacial + temporal
- */
- #include <stdio.h>
- #include <stdint.h>
- #include <string.h>
- #define ORDENADOR_SIZE 64
- #define TURNS_REQUIRED 3
- struct packet {
- uint8_t byte_value;
- };
- struct cell {
- struct packet *pkt;
- int age; // número de ciclos que já passou
- };
- static struct cell ordenador[ORDENADOR_SIZE];
- // Insere dado como "água" na entrada
- void inject_data(const uint8_t *data, size_t len) {
- memset(ordenador, 0, sizeof(ordenador));
- for (size_t i = 0; i < len && i < ORDENADOR_SIZE; i++) {
- static struct packet pkts[ORDENADOR_SIZE];
- pkts[i].byte_value = data[i];
- ordenador[i].pkt = &pkts[i];
- ordenador[i].age = 0;
- }
- }
- // Simula o "giro" do parafuso, empurrando dados
- void turn_ordenador() {
- for (int i = ORDENADOR_SIZE - 1; i > 0; i--) {
- if (!ordenador[i].pkt && ordenador[i - 1].pkt) {
- ordenador[i].pkt = ordenador[i - 1].pkt;
- ordenador[i].age = ordenador[i - 1].age + 1;
- ordenador[i - 1].pkt = NULL;
- }
- }
- }
- // Valida o buffer após N giros com XOR acumulado
- uint8_t compute_checksum() {
- uint8_t checksum = 0;
- for (int i = 0; i < ORDENADOR_SIZE; i++) {
- if (ordenador[i].pkt && ordenador[i].age >= TURNS_REQUIRED) {
- checksum ^= ordenador[i].pkt->byte_value;
- }
- }
- return checksum;
- }
- int main() {
- const uint8_t test_key[] = {0x12, 0x34, 0x56, 0x78};
- inject_data(test_key, sizeof(test_key));
- for (int i = 0; i < ORDENADOR_SIZE; i++) {
- turn_ordenador();
- }
- uint8_t final = compute_checksum();
- printf("Checksum final da chave: 0x%02X\n", final);
- // Validação esperada (exemplo)
- uint8_t expected = 0x12 ^ 0x34 ^ 0x56 ^ 0x78;
- if (final == expected) {
- printf("Chave VÁLIDA - passou pelo fluxo corretamente\n");
- } else {
- printf("Chave INVÁLIDA - fluxo incorreto ou dados adulterados\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement