static void mission_control_stop(MpcPeer mission_control, uint myid) { byte raw_pid[256] = {0}; Data _pid = Data_shallow(raw_pid, sizeof(raw_pid)); uint pid = getpid(); i2b(pid, _pid->data); i2b(myid, _pid->data+4); if (mission_control) { mission_control->send(_pid); } }
int main() { int x; scanf("%d",&x); i2b(x); //传入,并显示二进制 return 0; }
void rinode(uint inum, struct dinode *ip) { char buf[512]; uint bn; struct dinode *dip; bn = i2b(inum); rsect(bn, buf); dip = ((struct dinode *)buf) + (inum % IPB); *ip = *dip; }
void i2c_ds13x7_sync(uint32_t timestamp) { #ifdef CLOCK_DATETIME_SUPPORT ds13x7_reg_t rtc; struct clock_datetime_t d; memset( &rtc, 0, sizeof(rtc)); clock_localtime( &d, timestamp); rtc.ch = 0; rtc.sec = i2b( d.sec ); rtc.min = i2b( d.min ); rtc.hour = i2b( d.hour ); rtc.day = d.dow; rtc.date = i2b( d.day ); rtc.month = i2b( d.month ); rtc.century = (d.year>= 100 ? 1:0); rtc.year = i2b( d.year % 100 ); i2c_ds13x7_set_block( 0, (char *)&rtc, sizeof(rtc) ); // not the Ctrl reg #endif }
static void rand_bytes( byte * b, uint lb ) { uint i = 0; while(i+4 < lb) { int r = rand(); i2b(r,b+i); i+=4; } for(;i<lb;i++) { b[i] = (byte)rand(); } }
static int run(char * ip, uint myid, uint count, OE oe, MiniMacs mm) { CArena mc = CArena_new(oe); MpcPeer mission_control = 0; if (mc->connect("87.104.238.146", 65000).rc != 0) { oe->syslog(OSAL_LOGLEVEL_FATAL,"Failed to connect to the performance monitor."); return -1; }; mission_control = mc->get_peer(0); if (!mission_control) { oe->p("Failed connection to mission control. aborting.\n"); return -1; } if (mm->get_id() == 0) { if (mm->invite(1,2020+myid) != 0) { byte d[256] = {0}; char m[128] = {0}; osal_sprintf(m,"Failed to invite %u peers on port %u",1,2020+myid); oe->p(m); i2b(myid, d); osal_sprintf(d+4,"error"); mission_control->send(Data_shallow(d,128)); return 0; } } else { if (mm->connect(ip,2020+myid) != 0) { char m[128] = {0}; osal_sprintf(m,"Failed to connect to peer %s:%u",ip,2020+myid); oe->p(m); return 0; } } { byte key[128] = {0}; byte ptxt[128] = {0}; mpc_aes(mm,ptxt, key,myid,count,mission_control); CArena_destroy(&mc); } PrintMeasurements(oe); return 0; }
int gvprintf(writeCharFunc writeChar, char *fmt, va_list ap) { int len = 0; while(*fmt) { if (*fmt == '%') { uint8_t size = 2; // default size uint32_t mask = 0xFFFF; char f = 'd'; // default type fmt++; switch(*fmt) { case '1': size = 1; fmt++; break; case '2': size = 2; fmt++; break; case '4': size = 4; fmt++; break; } switch(*fmt) { case '%': outputChar(*fmt); break; case 's': { char *s = va_arg (ap, char *); while(*s) { outputChar(*s++); } } break; case 'S': { char *s = va_arg (ap, char *); char c; while((c = pgm_read_byte(s)) != '\0') { outputChar(c); s++; } } break; case 'c': { unsigned char c = (unsigned char)va_arg (ap, int /*char*/); outputChar(c); } break; case 'u': case 'd': case 'x': case 'b': { uint32_t v; switch (size) { case 1: v = va_arg (ap, int/*uint8_t*/); break; case 2: v = va_arg (ap, int/*uint16_t*/); break; case 4: v = va_arg (ap, uint32_t); break; } if (*fmt == 'x') { len += i2h(writeChar, v, size); } else if (*fmt == 'b') { len += i2b(writeChar, v, size); } else { len += i2d(writeChar, v, size, *fmt == 'd'); } } break; default: outputChar(*fmt); break; } fmt++; } else {
/* * ] Connect to the monitor * * ] Listen for clients with ids greater than this client. * * ] Connect to clients with ids less than this client. (in this way * client 1 connects to no one and listens for every one, vice verse * client N connects to everyone and listens for no one.) * * ] Execute mpc_aes with the connected peers * * ] Destroy the CArena connected to comm with the monitor and leave. */ static int run(char * ip, uint myid, uint count, OE oe, MiniMacs mm) { CArena mc = CArena_new(oe); MpcPeer mission_control = 0; // connect to monitor if (mc->connect(bitlab, 65000).rc != 0) { oe->syslog(OSAL_LOGLEVEL_FATAL,"Failed to connect to the performance monitor."); return -1; }; mission_control = mc->get_peer(0); if (!mission_control) { oe->p("Failed connection to mission control. aborting.\n"); return -1; } // listen for all parties with id greater than mm->myid { byte msg[92] = {0}; uint port = 2020+100*mm->get_id(); uint wait4=mm->get_no_players()-(mm->get_id()+1); osal_sprintf(msg,"Waiting for %u players to connect.",wait4); oe->p(msg); if (wait4 > 0) { if (mm->invite(wait4,port) != 0) { byte d[256] = {0}; char m[128] = {0}; osal_sprintf(m,"Failed to invite %u peers on port %u",wait4,2020+myid); oe->syslog(OSAL_LOGLEVEL_FATAL,m); i2b(myid, d); osal_sprintf(d+4,"error"); mission_control->send(Data_shallow(d,128)); return 0; }; } } // connect to all parties with id less than mm->myid { int id = 0; for(id = mm->get_id()-1;id >= 0;--id) { byte address[16] = {0}; byte msg[92] = {0}; uint port = 2020+100*id; osal_sprintf(msg,"connecting to %u ...",port); oe->p(msg); osal_sprintf(address,"10.11.82.%d",id+1); if (mm->connect(address,port) != 0) { byte d[256] = {0}; char m[128] = {0}; osal_sprintf(m,"Failed to connect to %s peers on port %u",address,port); oe->syslog(OSAL_LOGLEVEL_FATAL,m); i2b(myid, d); osal_sprintf(d+4,"error"); mission_control->send(Data_shallow(d,128)); return 0; } } } // invoke AES circuit with zero plaintext and zero key { byte key[128] = {0}; byte ptxt[128] = {0}; mpc_aes(mm,ptxt, key,myid,count,mission_control); CArena_destroy(&mc); } // print time measurements if compiled in PrintMeasurements(oe); return 0; }
static void XN_CALLBACK_TYPE s_onCalibrationEnd(SkeletonCapability& capability, XnUserID userID, XnBool isSuccess, void* that) { this_cast(that)->onCalibrationEnd(userID, i2b(isSuccess)); }
void i2b(int n) //接收传入的整数值 { if(n==0) return; //跳出 i2b(n/2); printf("%d",n%2); }