COSA
An Object-Oriented Platform for Arduino Programming
RC4.cpp
Go to the documentation of this file.
1 
21 #include "RC4.hh"
22 
23 void
24 RC4::restart(const void* key, size_t len)
25 {
26  for (uint16_t i = 0; i < sizeof(m_state); i++)
27  m_state[i] = i;
28 
29  m_x = 0;
30  m_y = 0;
31 
32  const uint8_t* buf = (const uint8_t*) key;
33  uint8_t j = 0;
34  for (uint16_t i = 0; i < 256; i++) {
35  j = j + m_state[i] + buf[i % len];
36  uint8_t tmp = m_state[i];
37  m_state[i] = m_state[j];
38  m_state[j] = tmp;
39  }
40 }
41 
void restart(const void *key, size_t len)
Definition: RC4.cpp:24