int main(void) { printf("This program is RSA Cryptosystem\n\n"); printf("暗号:1 復号:2 終了:0 を選択してください>"); while (1){ int c = getch(); printf("%c", c); if (c == '1'){ printf("\n暗号化します.\n\n"); An(); printf("\n暗号:1 復号:2 終了:0 を選択してください>"); } else if (c == '2'){ printf("\n復号化します.\n\n"); Fuku(); printf("\n暗号:1 復号:2 終了:0 を選択してください>"); } else if (c == '0'){ printf("\n正常終了\n"); return 0; } else{ printf("\n暗号:1 復号:2 終了:0 を選択してください>"); } } return 0; }
// Calculates the total probability flux leaving the domain at time t // This is simply the negative of the time derivative of the survival prob. // at time t [-dS(t')/dt' for t'=t]. Real GreensFunction1DRadAbs::flux_tot (Real t) const { Real root_n; const Real D(this->getD()); const Real v(this->getv()); const Real vexpo(-v*v*t/4.0/D - v*r0/2.0/D); const Real D2 = D*D; const Real v2Dv2D = v*v/4.0/D2; double sum = 0, term = 0, prev_term = 0; int n=1; do { if ( n >= MAX_TERMS ) { std::cerr << "Too many terms needed for GF1DRad::flux_tot. N: " << n << std::endl; break; } root_n = this->root_n(n); prev_term = term; term = (root_n * root_n + v2Dv2D) * Cn(root_n, t) * An(root_n) * Bn(root_n); n++; sum += term; } while (fabs(term/sum) > EPSILON*PDENS_TYPICAL || fabs(prev_term/sum) > EPSILON*PDENS_TYPICAL || n <= MIN_TERMS ); return 2.0*D*exp(vexpo)*sum; }
// Calculates the probability density of finding the particle at location r at // time t. const Real FirstPassageGreensFunction1DRad::prob_r (const Real r, const Real t) const { const Real L(this->getL()); const Real D(this->getD()); const Real h(this->getk()/D); const Real r0(this->getr0()); THROW_UNLESS( std::invalid_argument, t >= 0.0 ); THROW_UNLESS( std::invalid_argument, 0 <= r && r <= L); // if there was no time or no movement if (t == 0 || D == 0) { // the probability density function is a delta function if (r == r0) { return INFINITY; } else { return 0.0; } } // if you're looking on the boundary if ( fabs (r - L) < EPSILON*L ) { return 0.0; } Real root_n, An_r; Real sum = 0, term = 0, prev_term = 0; int n=1; do { if ( n >= MAX_TERMEN ) { std::cerr << "Too many terms needed for GF1DRad::prob_r. N: " << n << std::endl; break; } root_n = this->a_n(n); An_r = root_n*r; prev_term = term; term = Cn(root_n, t) * An(root_n) * (root_n*cos(An_r) + h*sin(An_r)); sum += term; n++; } // PDENS_TYPICAL is now 1e3, is this any good?! while (fabs(term/sum) > EPSILON*PDENS_TYPICAL || fabs(prev_term/sum) > EPSILON*PDENS_TYPICAL || n <= MIN_TERMEN ); return 2.0*sum; }
static void chest_shatter_msg(struct obj *otmp) { const char *disposition; const char *thing; long save_Blinded; if (otmp->oclass == POTION_CLASS) { pline(msgc_itemloss, "You %s %s shatter!", Blind ? "hear" : "see", an(bottlename())); if (!breathless(youmonst.data) || haseyes(youmonst.data)) potionbreathe(&youmonst, otmp); return; } /* We have functions for distant and singular names, but not one which does _both_... TODO: fix this blindness kludge (it doesn't even work -- see eoto) */ save_Blinded = property_timeout(&youmonst, BLINDED); set_property(&youmonst, BLINDED, 1, TRUE); thing = singular(otmp, xname); if (save_Blinded) set_property(&youmonst, BLINDED, save_Blinded, TRUE); switch (objects[otmp->otyp].oc_material) { case PAPER: disposition = "is torn to shreds"; break; case WAX: disposition = "is crushed"; break; case VEGGY: disposition = "is pulped"; break; case FLESH: disposition = "is mashed"; break; case GLASS: disposition = "shatters"; break; case WOOD: disposition = "splinters to fragments"; break; default: disposition = "is destroyed"; break; } pline(msgc_itemloss, "%s %s!", An(thing), disposition); }
double RkPdf::MfRk(const double& x, const double& tau, const double& dm){ const double r_ckak = ck/ak; const double inv_ak = 1.0/ak; const double ndmtau = r_ckak*dm*tau; const double fact = 1.0/(1.0+ndmtau*ndmtau); double Li = 0.0; if(x<0.0){ const double ndm = dm/(ak-ck); const double ntau = tau*(ak-ck); Li = inv_ak*fact*(Mn(x,ntau,ndm)+ndmtau*An(x,ntau,ndm)); }else{ const double ndm = dm/(ak+ck); const double ntau = tau*(ak+ck); Li = inv_ak*fact*(Mp(x,ntau,ndm)+ndmtau*Ap(x,ntau,ndm)); } return Li; }
static void convert_line (void) { char *c, *cc; char xbuf[BUFSZ]; cc = out_line; for (c = xcrypt(in_line, xbuf); *c; c++) { *cc = 0; switch(*c) { case '\r': case '\n': *(++cc) = 0; return; case '%': if (*(c+1)) { convert_arg(*(++c)); switch (*(++c)) { /* insert "a"/"an" prefix */ case 'A': strcat(cc, An(cvt_buf)); cc += strlen(cc); continue; /* for */ case 'a': strcat(cc, an(cvt_buf)); cc += strlen(cc); continue; /* for */ /* capitalize */ case 'C': cvt_buf[0] = highc(cvt_buf[0]); break; /* pluralize */ case 'P': cvt_buf[0] = highc(cvt_buf[0]); case 'p': strcpy(cvt_buf, makeplural(cvt_buf)); break; /* append possessive suffix */ case 'S': cvt_buf[0] = highc(cvt_buf[0]); case 's': strcpy(cvt_buf, "TODO: s_suffix(cvt_buf)"); break; /* strip any "the" prefix */ case 't': if (!strncmpi(cvt_buf, "the ", 4)) { strcat(cc, &cvt_buf[4]); cc += strlen(cc); continue; /* for */ } break; default: --c; /* undo switch increment */ break; } strcat(cc, cvt_buf); cc += strlen(cvt_buf); break; } /* else fall through */ default: *cc++ = *c; break; } } if (cc >= out_line + sizeof out_line) panic("convert_line: overflow"); *cc = 0; return; }
func Initialize() { An(); return(1); }
Point Gerade::Schnitt(Gerade &G) { //neuer Ansatz Matrix An(2,2,Null); Matrix xn; Matrix bn(2,1,Null); Point G1O; G1O=(*this).get_O(); //Ortsvektor Point G1R; G1R=(*this).get_R(); //Richtungsvektor Point G2O; G2O=G.get_O(); //Ortsvektor Point G2R; G2R=G.get_R(); //Richtungsvektor double x1n= G1R.get_X()*G1R.get_X()+G1R.get_Y()*G1R.get_Y()+G1R.get_Z()*G1R.get_Z(); double x2n=-G1R.get_X()*G2R.get_X()-G1R.get_Y()*G2R.get_Y()-G1R.get_Z()*G2R.get_Z(); double x3n= G1R.get_X()*G2R.get_X()+G1R.get_Y()*G2R.get_Y()+G1R.get_Z()*G2R.get_Z(); double x4n=-G2R.get_X()*G2R.get_X()-G2R.get_Y()*G2R.get_Y()-G2R.get_Z()*G2R.get_Z(); An(0,0)=x1n; An(0,1)=x2n; An(1,0)=x3n; An(1,1)=x4n; double b1n=-G1O.get_X()*G1R.get_X()+G2O.get_X()*G1R.get_X() -G1O.get_Y()*G1R.get_Y()+G2O.get_Y()*G1R.get_Y() -G1O.get_Z()*G1R.get_Z()+G2O.get_Z()*G1R.get_Z(); double b2n=-G1O.get_X()*G2R.get_X()+G2O.get_X()*G2R.get_X() -G1O.get_Y()*G2R.get_Y()+G2O.get_Y()*G2R.get_Y() -G1O.get_Z()*G2R.get_Z()+G2O.get_Z()*G2R.get_Z(); bn(0,0)=b1n; bn(1,0)=b2n; xn=An.MatInvert().MatMult( bn ); Point Sn,S1n,S2n; S1n = (*this).get_O().Add( (*this).get_R().MultS( xn(0,0) ) ); S2n = G.get_O().Add( G.get_R().MultS( xn(1,0) ) ); Sn.set_X( (S1n.get_X()+S2n.get_X())/2.0); Sn.set_Y( (S1n.get_Y()+S2n.get_Y())/2.0); Sn.set_Z( (S1n.get_Z()+S2n.get_Z())/2.0); Sn.set_dX( (S1n.get_X()-S2n.get_X())/2.0); Sn.set_dY( (S1n.get_Y()-S2n.get_Y())/2.0); Sn.set_dZ( (S1n.get_Z()-S2n.get_Z())/2.0); //Gleichnugssystem Ax=b Matrix A(2,2,Null); Matrix x; Matrix b(2,1,Null); /* Point G1O; G1O=(*this).getO(); //Ortsvektor Point G1R; G1R=(*this).getR(); //Richtungsvektor Point G2O; G2O=G.getO(); //Ortsvektor Point G2R; G2R=G.getR(); //Richtungsvektor */ double x1=G1R.get_X(); double x2=(-1)*G2R.get_X(); double x3=G1R.get_Y(); double x4=(-1)*G2R.get_Y(); A(0,0)=x1; A(0,1)=x2; A(1,0)=x3; A(1,1)=x4; double b1=G2O.get_X()-G1O.get_X(); double b2=G2O.get_Y()-G1O.get_Y(); b(0,0)=b1; b(1,0)=b2; x=A.MatInvert().MatMult( b ); Point S,S1,S2; S1 = (*this).get_O().Add( (*this).get_R().MultS( x(0,0) ) ); S2 = G.get_O().Add( G.get_R().MultS( x(1,0) ) ); S.set_X( (S1.get_X()+S2.get_X())/2.0); S.set_Y( (S1.get_Y()+S2.get_Y())/2.0); S.set_Z( (S1.get_Z()+S2.get_Z())/2.0); S.set_dX( (S1.get_X()-S2.get_X())/2.0); S.set_dY( (S1.get_Y()-S2.get_Y())/2.0); S.set_dZ( (S1.get_Z()-S2.get_Z())/2.0); return Sn; }
// Calculates the probability density of finding the particle at location r // at time t. Real GreensFunction1DRadAbs::prob_r (Real r, Real t) const { THROW_UNLESS( std::invalid_argument, t >= 0.0 ); THROW_UNLESS( std::invalid_argument, (r-sigma) >= 0.0 && r <= a && (r0 - sigma) >= 0.0 && r0<=a ); const Real sigma(this->getsigma()); const Real a(this->geta()); const Real L(this->geta()-this->getsigma()); const Real r0(this->getr0()); const Real D(this->getD()); const Real v(this->getv()); const Real h((this->getk()+this->getv()/2.0)/this->getD()); const Real vexpo(-v*v*t/D/4.0 + v*(r-r0)/D/2.0); // if there was no time change or zero diffusivity => no movement if (t == 0 || D == 0) { // the probability density function is a delta function if (r == r0) { return INFINITY; } else { return 0.0; } } // if r is at the absorbing boundary if ( fabs(a-r) < EPSILON*L ) { return 0.0; } Real root_n, root_n_r_s; Real sum = 0, term = 0, prev_term = 0; int n=1; do { if ( n >= MAX_TERMS ) { std::cerr << "Too many terms needed for GF1DRad::prob_r. N: " << n << std::endl; break; } root_n = this->root_n(n); root_n_r_s = root_n*(r-sigma); prev_term = term; term = Cn(root_n, t) * An(root_n) * (h*sin(root_n_r_s) + root_n*cos(root_n_r_s)); sum += term; n++; } while (fabs(term/sum) > EPSILON*PDENS_TYPICAL || fabs(prev_term/sum) > EPSILON*PDENS_TYPICAL || n <= MIN_TERMS ); return 2.0*exp(vexpo)*sum; }
void tty_player_selection() { char pbuf[QBUFSZ]; char pick, pc; int i, linecount; linecount = wins[BASE_WINDOW]->cury+1; if ((pc = highc(pl_character[0])) != 0) { if(index(pl_classes, pc) != (char*) 0) goto got_suffix; tty_putstr(BASE_WINDOW, 0, ""); Sprintf(pbuf, "Unknown role: %c", pc); tty_putstr(BASE_WINDOW, 0, pbuf); linecount += 2; pl_character[0] = pc = 0; } #define PICK_PROMPT "Shall I pick a character for you? [Y, N, or Q(quit)] " tty_putstr(BASE_WINDOW, 0, ""); tty_putstr(BASE_WINDOW, 0, PICK_PROMPT); while(!index("yYnNqQ", (pick = readchar())) && !index(quitchars, pick)) tty_nhbell(); pick = index(quitchars, pick) ? 'Y' : highc(pick); tty_putsym(BASE_WINDOW, (int)strlen(PICK_PROMPT)+1, linecount, pick); /* echo */ if (pick == 'Q') { clearlocks(); tty_exit_nhwindows(NULL); terminate(0); } if (pick == 'Y') { tty_putstr(BASE_WINDOW, 0, ""); goto beginner; } tty_curs(BASE_WINDOW, 1, linecount+2); tty_putstr(BASE_WINDOW, 0, "What kind of character are you:"); tty_putstr(BASE_WINDOW, 0, ""); Sprintf(pbuf, " %s,", An(roles[0])); for(i = 1; roles[i]; i++) { Sprintf(eos(pbuf), " %s", an(roles[i])); if((((i + 1) % 4) == 0) && roles[i+1]) { Strcat(pbuf, ","); tty_putstr(BASE_WINDOW, 0, pbuf); linecount++; Strcpy(pbuf, " "); } else if(roles[i+1] && roles[i+2]) Strcat(pbuf, ","); if(roles[i+1] && !roles[i+2]) Strcat(pbuf, " or"); } Strcat(pbuf ,"?"); tty_putstr(BASE_WINDOW, 0, pbuf); Strcpy(pbuf, " ["); for(i = 0; roles[i]; i++) Sprintf(eos(pbuf), "%c,", pl_classes[i]); Strcat(pbuf, " or Q] "); tty_putstr(BASE_WINDOW, 0, pbuf); linecount += 5; while ((pc = readchar()) != 0) { if ((pc = highc(pc)) == 'Q') { clearlocks(); tty_exit_nhwindows(NULL); terminate(0); } if(index(pl_classes, pc) != (char *) 0) { tty_putsym(BASE_WINDOW, (int)strlen(pbuf)+1, linecount, pc); /* echo */ tty_putstr(BASE_WINDOW, 0, ""); tty_display_nhwindow(BASE_WINDOW, TRUE); break; } if(pc == '\n') { pc = 0; break; } tty_nhbell(); } beginner: if(!pc) { i = rn2((int)strlen(pl_classes)); pc = pl_classes[i]; tty_putstr(BASE_WINDOW, 0, ""); Sprintf(pbuf, "This game you will be %s.", an(roles[i])); tty_putstr(BASE_WINDOW, 0, pbuf); tty_putstr(BASE_WINDOW, 0, ""); tty_display_nhwindow(BASE_WINDOW, TRUE); getret(); } got_suffix: tty_clear_nhwindow(BASE_WINDOW); pl_character[0] = pc; return; }
static const char * convert_line(const char *in_line) { /* xcrypt needs us to allocate a buffer for it */ char decrypted_line[strlen(in_line)+1]; xcrypt(in_line, decrypted_line); const char *rv = ""; char *c; /* Tokenize the decrypted line; we stop at \r, \n, or \0, and do special handling of "%" characters. The algorithm used here is quadratic (when linear is possible), but given that the lines are only 80 characters long, I feel that a clear algorithm is superior to a low computational complexity algorithm. */ for (c = xcrypt(in_line, decrypted_line);; c++) { switch (*c) { case '\r': case '\n': case '\0': return rv; case '%': if (c[1]) { const char *conversion = convert_arg(*(++c)); switch (*(++c)) { /* insert "a"/"an" prefix */ case 'A': rv = msgcat(rv, An(conversion)); break; case 'a': rv = msgcat(rv, an(conversion)); break; /* capitalize */ case 'C': rv = msgcat(rv, msgupcasefirst(conversion)); break; /* pluralize */ case 'P': /* Note: makeplural doesn't work on arbitrarily capitalized strings */ rv = msgcat(rv, msgupcasefirst(makeplural(conversion))); break; case 'p': rv = msgcat(rv, makeplural(conversion)); break; /* append possessive suffix */ case 'S': conversion = msgupcasefirst(conversion); /* fall through */ case 's': rv = msgcat(rv, s_suffix(conversion)); break; /* strip any "the" prefix */ case 't': if (!strncmpi(conversion, "the ", 4)) rv = msgcat(rv, conversion + 4); else rv = msgcat(rv, conversion); break; default: --c; /* undo switch increment */ rv = msgcat(rv, conversion); break; } break; } /* else fall through */ default: rv = msgkitten(rv, *c); break; } } }