Coder Social home page Coder Social logo

Adding more than one card about magspoof HOT 5 CLOSED

samyk avatar samyk commented on July 24, 2024
Adding more than one card

from magspoof.

Comments (5)

fantuz avatar fantuz commented on July 24, 2024

The quality of code seems pretty high, implements all the best practices to avoid delays and minimise number of calls or iterations of the such (all the shifts and beauty).

Though, I have to point out 3 things you could improve:

  • you post the code but not stating "which" is the problem... no luck
  • you open a thread on another forum, that needs login to comment... why then double posting the same text without the most basic hint for a debugger, an information on why your code is failing ?
  • you could fork the project, do the modifications and discussions issues on your branch, then create a pull request to the owner.

Sorry, I will even try to help you as I love both Sami works and microcontrollers ... I would even try to compile in my avrdude to see if anything bad pops up, but you shall at least specify how the specific/unknown issue reproduces/manifests.... am I missing some other discussion, that is not referenced by your post here ?

Apologise me if I am OT/wrong.

from magspoof.

martianman1999 avatar martianman1999 commented on July 24, 2024

Thank you very much for your reply I'm very new to programing and how to properly post of forums. My problem is that I am unsure what the proper name and avenue I should be taking I have a general idea on what the code should look like but the OG code is very complex and I am trying to preserve it's functionality.
Also sorry I didn't know you needed a login to see the post.

from magspoof.

martianman1999 avatar martianman1999 commented on July 24, 2024

The code I am using is:

/*

  • MagSpoof - "wireless" magnetic stripe/credit card emulator
  • by Samy Kamkar
  • http://samy.pl/magspoof/
    • Allows you to store all of your credit cards and magstripes in one device
    • Works on traditional magstripe readers wirelessly (no NFC/RFID required)
    • Can disable Chip-and-PIN (code not included)
    • Correctly predicts Amex credit card numbers + expirations from previous card number (code not included)
    • Supports all three magnetic stripe tracks, and even supports Track 1+2 simultaneously
    • Easy to build using Arduino or ATtiny

*/
#include <avr/sleep.h>
#include <avr/interrupt.h>

#define PIN_A 0
#define PIN_B 1
#define ENABLE_PIN 3 // also green LED
#define SWAP_PIN 4 // unused
#define BUTTON_PIN 2 // Send Tracks
#define CLOCK_US 200
#define BETWEEN_ZERO 53 // 53 zeros between track1 & 2
#define TRACKS 2
/New Varables/

#define PINCARD1 8
#define PINCARD2 9
#define PINCARD3 10

// consts get stored in flash as we don't adjust them
const char* CARD1[] =
{
"%Card1^LASTNAME/FIRST^YYMMSSSDDDDDDDDDDDDDDDDDDDDDDDDD?\0", // Track 1
";123456781234567=YYMMSSSDDDDDDDDDDDDDD?\0" // Track 2
};

const char* CARD2[] =
{
"%Card2^LASTNAME/FIRST^YYMMSSSDDDDDDDDDDDDDDDDDDDDDDDDD?\0", // Track 1
";123456781234567=YYMMSSSDDDDDDDDDDDDDD?\0" // Track 2
};

const char* CARD3[] =
{
"%Card3^LASTNAME/FIRST^YYMMSSSDDDDDDDDDDDDDDDDDDDDDDDDD?\0", // Track 1
";123456781234567=YYMMSSSDDDDDDDDDDDDDD?\0" // Track 2
};

/*
const char* tracks[] =
{
"%B123456781234567^LASTNAME/FIRST^YYMMSSSDDDDDDDDDDDDDDDDDDDDDDDDD?\0", // Track 1
";123456781234567=YYMMSSSDDDDDDDDDDDDDD?\0" // Track 2
};
*/

char revTrack[41];

const int sublen[] = {
32, 48, 48 };
const int bitlen[] = {
7, 5, 5 };

unsigned int curTrack = 0;
int dir;

void setup()
{
pinMode(PIN_A, OUTPUT);
pinMode(PIN_B, OUTPUT);
pinMode(ENABLE_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);

pinMode(PINCARD1, INPUT_PULLUP);
pinMode(PINCARD2, INPUT_PULLUP);
pinMode(PINCARD3, INPUT_PULLUP);

// blink to show we started up
blink(ENABLE_PIN, 200, 3);

// store reverse track 2 to play later
storeRevTrack(2);
}

void blink(int pin, int msdelay, int times)
{
for (int i = 0; i < times; i++)
{
digitalWrite(pin, HIGH);
delay(msdelay);
digitalWrite(pin, LOW);
delay(msdelay);
}
}

// send a single bit out
void playBit(int sendBit)
{
dir ^= 1;
digitalWrite(PIN_A, dir);
digitalWrite(PIN_B, !dir);
delayMicroseconds(CLOCK_US);

if (sendBit)
{
dir ^= 1;
digitalWrite(PIN_A, dir);
digitalWrite(PIN_B, !dir);
}
delayMicroseconds(CLOCK_US);

}

// when reversing
void reverseTrack(int track)
{
int i = 0;
track--; // index 0
dir = 0;

while (revTrack[i++] != '\0');
i--;
while (i--)
for (int j = bitlen[track]-1; j >= 0; j--)
playBit((revTrack[i] >> j) & 1);
}

// plays out a full track, calculating CRCs and LRC
void playTrack(int track)
{
int tmp, crc, lrc = 0;
track--; // index 0
dir = 0;

// enable H-bridge and LED
digitalWrite(ENABLE_PIN, HIGH);

// First put out a bunch of leading zeros.
for (int i = 0; i < 25; i++)
playBit(0);

//
for (int i = 0; tracks[track][i] != '\0'; i++)
{
crc = 1;
tmp = tracks[track][i] - sublen[track];

for (int j = 0; j < bitlen[track]-1; j++)
{
  crc ^= tmp & 1;
  lrc ^= (tmp & 1) << j;
  playBit(tmp & 1);
  tmp >>= 1;
}
playBit(crc);

}

// finish calculating and send last "byte" (LRC)
tmp = lrc;
crc = 1;
for (int j = 0; j < bitlen[track]-1; j++)
{
crc ^= tmp & 1;
playBit(tmp & 1);
tmp >>= 1;
}
playBit(crc);

// if track 1, play 2nd track in reverse (like swiping back?)
if (track == 0)
{
// if track 1, also play track 2 in reverse
// zeros in between
for (int i = 0; i < BETWEEN_ZERO; i++)
playBit(0);

// send second track in reverse
reverseTrack(2);

}

// finish with 0's
for (int i = 0; i < 5 * 5; i++)
playBit(0);

digitalWrite(PIN_A, LOW);
digitalWrite(PIN_B, LOW);
digitalWrite(ENABLE_PIN, LOW);

}

// stores track for reverse usage later
void storeRevTrack(int track)
{
int i, tmp, crc, lrc = 0;
track--; // index 0
dir = 0;

for (i = 0; tracks[track][i] != '\0'; i++)
{
crc = 1;
tmp = tracks[track][i] - sublen[track];

for (int j = 0; j < bitlen[track]-1; j++)
{
  crc ^= tmp & 1;
  lrc ^= (tmp & 1) << j;
  tmp & 1 ?
    (revTrack[i] |= 1 << j) :
    (revTrack[i] &= ~(1 << j));
  tmp >>= 1;
}
crc ?
  (revTrack[i] |= 1 << 4) :
  (revTrack[i] &= ~(1 << 4));

}

// finish calculating and send last "byte" (LRC)
tmp = lrc;
crc = 1;
for (int j = 0; j < bitlen[track]-1; j++)
{
crc ^= tmp & 1;
tmp & 1 ?
(revTrack[i] |= 1 << j) :
(revTrack[i] &= ~(1 << j));
tmp >>= 1;
}
crc ?
(revTrack[i] |= 1 << 4) :
(revTrack[i] &= ~(1 << 4));

i++;
revTrack[i] = '\0';
}

void sleep()
{
GIMSK |= _BV(PCIE); // Enable Pin Change Interrupts
PCMSK |= _BV(PCINT2); // Use PB3 as interrupt pin
ADCSRA &= ~_BV(ADEN); // ADC off
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // replaces above statement

MCUCR &= ~_BV(ISC01);
MCUCR &= ~_BV(ISC00); // Interrupt on rising edge
sleep_enable(); // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
sei(); // Enable interrupts
sleep_cpu(); // sleep

cli(); // Disable interrupts
PCMSK &= ~_BV(PCINT2); // Turn off PB3 as interrupt pin
sleep_disable(); // Clear SE bit
ADCSRA |= _BV(ADEN); // ADC on

sei(); // Enable interrupts
}

// XXX move playtrack in here?
ISR(PCINT0_vect) {
/* noInterrupts();
while (digitalRead(BUTTON_PIN) == LOW);
delay(50);
while (digitalRead(BUTTON_PIN) == LOW);
playTrack(1 + (curTrack++ % 2));
delay(400);
interrupts();*/

}

void loop()
{
#define tracks[]

if (PINCARD1, LOW)
{
tracks[] = CARD1;
}
if (PINCARD2, LOW)
{
tracks [] = CARD2;
}
if (PINCARD3, LOW)
{
tracks[] = CARD3;
}

//for(int i=0;i<10;i++){playTrack(1+(curTrack++%2));delay(3000);}

sleep();

noInterrupts();
while (digitalRead(BUTTON_PIN) == LOW);

delay(50);
while (digitalRead(BUTTON_PIN) == LOW);
playTrack(1 + (curTrack++ % 2));
delay(400);

interrupts();
//playTrack(1 + (curTrack++ % 2));
}

from magspoof.

fantuz avatar fantuz commented on July 24, 2024

Sorry sorry i do not want to tear you down, just saying that this is not the right place to trow "generic" questions.

Probably in terms of questions about coding/implementation, arduino forum is still the right place to post and learn from, unless is a more logic/abstract thing that has interested in being shared between github and arduino forum itself. Anyway, you are linking two different communities, projects, mailing lists.... spamming the world :D if you are new, better to learn how to pose questions in a way that your effort will receive an answer, otherwise it will stay a mute thread (and be a loss of time to close the issue).

Even more you propose a "feature" so you should really fork, it might be easier for people to contribute more effectively (by pull request as said).
Look at the top-righ button at any repository frontpage, there will be a "FORK" button.

from magspoof.

martianman1999 avatar martianman1999 commented on July 24, 2024

Thank you very much

from magspoof.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.