bsddeamon

hack

Apr 23rd, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. // Mifare Ultracard writer
  2. // Written by: Samuel Duclos
  3. // Creative Commons License
  4.  
  5. #include <SPI.h>
  6. #include <MFRC522.h>
  7.  
  8. #define RST_PIN 9
  9. #define SS_PIN 10
  10.  
  11. char i = 0, k = 0, input[] = {',',',',',',',',',',',',',',','};
  12. byte page = 0, buffer[4];
  13.  
  14. MFRC522 mfrc522(SS_PIN, RST_PIN);
  15.  
  16. void setup() {
  17.   Serial.begin(9600);
  18.   SPI.begin();
  19.   mfrc522.PCD_Init();
  20.   Serial.println("Ultracard writer by Samuel Duclos, under Creative Commons License");
  21.   Serial.println("Writings to pages 2 and 3 are permanent!!");
  22.   Serial.println("Enter page# [02-0F]:");
  23. }
  24.  
  25. void loop() {
  26.   while (!Serial.available());
  27.   Serial.readBytesUntil('\n', input, 6);
  28.   page = (byte)strtol((char *)input, NULL, 16);
  29.   Serial.println("Enter 4 bytes separated by \"ENTER\" strokes:");
  30.  
  31.   do {
  32.     // for(char j = 0; j < sizeof(input); j++) input[j] = 0;
  33.     memset(input, 0, sizeof(input));
  34.     k = Serial.available();
  35.     while (k == Serial.available());
  36.     Serial.readBytesUntil('\n', input, 6);
  37.     buffer[i] = (byte)strtol((char *)input, NULL, 16);
  38.   } while (++i < 3);
  39.  
  40. Serial.println("You may now scan the card...");
  41.  
  42.   while (1) {
  43.     if(!mfrc522.PICC_IsNewCardPresent()) continue;
  44.     if (!mfrc522.PICC_ReadCardSerial()) continue;
  45.     Serial.println(
  46.       mfrc522.GetStatusCodeName(
  47.         mfrc522.MIFARE_Ultralight_Write(
  48.           page, (byte *)buffer, 4)));
  49.   }
  50. }
Add Comment
Please, Sign In to add comment