int command_rot13 (int argc, char **argv) { int i, rotate = 13; char *ptr; progname = argv[0]; in = stdin; for (i = 1; i < argc; ++i) { ptr = argv[i]; if (*ptr == '-') { switch (*++ptr) { case '\0': in = stdin; break; case '-': if (!strcmp (ptr, "-help")) puts (help_text); else if (!strcmp (ptr, "-version")) puts ("rot13: version "VERSION); else terror ("invalid option `%s'", argv[i]); return (EXIT_SUCCESS); case 'a': flag_ascii = 1; break; case 'r': if (*++ptr != '\0') ; else if (++i < argc) ptr = argv[i]; else terror ("missing operand to `-r' option"); rotate = getnum_ul (ptr); break; } } else { fclose (in); in = xfopen (argv[i], "r"); } do_rot13 (rotate); } if (flag_done == 0) do_rot13 (rotate); fclose (in); return (EXIT_SUCCESS); }
/** * A simple non-UI mechanism. */ static OSStatus invokeRot13(MechanismRef *mechanism) { AuthorizationContextFlags contextFlags; const AuthorizationValue *value; AuthorizationValue newValue = {}; OSStatus status; status = mechanism->plugin->callbacks->GetContextValue(mechanism->engine, kAuthorizationEnvironmentPassword, &contextFlags, &value); if (status) return status; newValue.length = value->length; newValue.data = malloc(newValue.length); do_rot13(newValue.data, value->data, newValue.length); syslog(LOG_ERR, "old: %*s new: %*s", value->length, (const char *)value->data, newValue.length, (const char *)newValue.data); status = mechanism->plugin->callbacks->SetContextValue(mechanism->engine, kAuthorizationEnvironmentPassword, contextFlags, &newValue); if (newValue.data) free(newValue.data); return status; }
void Crypter::doRot13() { for(int i = 0; i < w.size(); i++) { int r = do_rot13(w.at(i).toAscii()); if(r) { w[i] = QChar(r); } } }