/*
* SHA-256 implementation, Mark 2
*
* Copyright (c) 2010,2014 Ilya O. Levin, http://www.literatecode.com
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "sha256.h"
/* #define MINIMIZE_STACK_IMPACT */ #ifdef __cplusplus
extern "C" {
#endif #define FN_ inline static static const uint32_t K[64] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
}; #ifdef MINIMIZE_STACK_IMPACT
static uint32_t W[64];
#endif /* -------------------------------------------------------------------------- */
FN_ uint8_t _shb(uint32_t x, uint32_t n)
{
return ( (x >> (n & 31)) & 0xff );
} /* _shb */ /* -------------------------------------------------------------------------- */
FN_ uint32_t _shw(uint32_t x, uint32_t n)
{
return ( (x << (n & 31)) & 0xffffffff );
} /* _shw */ /* -------------------------------------------------------------------------- */
FN_ uint32_t _r(uint32_t x, uint8_t n)
{
return ( (x >> n) | _shw(x, 32 - n) );
} /* _r */ /* -------------------------------------------------------------------------- */
FN_ uint32_t _Ch(uint32_t x, uint32_t y, uint32_t z)
{
return ( (x & y) ^ ((~x) & z) );
} /* _Ch */ /* -------------------------------------------------------------------------- */
FN_ uint32_t _Ma(uint32_t x, uint32_t y, uint32_t z)
{
return ( (x & y) ^ (x & z) ^ (y & z) );
} /* _Ma */ /* -------------------------------------------------------------------------- */
FN_ uint32_t _S0(uint32_t x)
{
return ( _r(x, 2) ^ _r(x, 13) ^ _r(x, 22) );
} /* _S0 */ /* -------------------------------------------------------------------------- */
FN_ uint32_t _S1(uint32_t x)
{
return ( _r(x, 6) ^ _r(x, 11) ^ _r(x, 25) );
} /* _S1 */ /* -------------------------------------------------------------------------- */
FN_ uint32_t _G0(uint32_t x)
{
return ( _r(x, 7) ^ _r(x, 18) ^ (x >> 3) );
} /* _G0 */ /* -------------------------------------------------------------------------- */
FN_ uint32_t _G1(uint32_t x)
{
return ( _r(x, 17) ^ _r(x, 19) ^ (x >> 10) );
} /* _G1 */ /* -------------------------------------------------------------------------- */
FN_ uint32_t _word(uint8_t *c)
{
return ( _shw(c[0], 24) | _shw(c[1], 16) | _shw(c[2], 8) | (c[3]) );
} /* _word */ /* -------------------------------------------------------------------------- */
FN_ void _addbits(sha256_context *ctx, uint32_t n)
{
if ( ctx->bits[0] > (0xffffffff - n) )
ctx->bits[1] = (ctx->bits[1] + 1) & 0xFFFFFFFF;
ctx->bits[0] = (ctx->bits[0] + n) & 0xFFFFFFFF;
} /* _addbits */ /* -------------------------------------------------------------------------- */
static void _hash(sha256_context *ctx)
{
register uint32_t a, b, c, d, e, f, g, h, i;
uint32_t t[2];
#ifndef MINIMIZE_STACK_IMPACT
uint32_t W[64];
#endif a = ctx->hash[0];
b = ctx->hash[1];
c = ctx->hash[2];
d = ctx->hash[3];
e = ctx->hash[4];
f = ctx->hash[5];
g = ctx->hash[6];
h = ctx->hash[7]; for (i = 0; i < 64; i++) {
if ( i < 16 )
W[i] = _word(&ctx->buf[_shw(i, 2)]);
else
W[i] = _G1(W[i - 2]) + W[i - 7] + _G0(W[i - 15]) + W[i - 16]; t[0] = h + _S1(e) + _Ch(e, f, g) + K[i] + W[i];
t[1] = _S0(a) + _Ma(a, b, c);
h = g;
g = f;
f = e;
e = d + t[0];
d = c;
c = b;
b = a;
a = t[0] + t[1];
} ctx->hash[0] += a;
ctx->hash[1] += b;
ctx->hash[2] += c;
ctx->hash[3] += d;
ctx->hash[4] += e;
ctx->hash[5] += f;
ctx->hash[6] += g;
ctx->hash[7] += h;
} /* _hash */ /* -------------------------------------------------------------------------- */
void sha256_init(sha256_context *ctx)
{
if ( ctx != NULL ) {
ctx->bits[0] = ctx->bits[1] = 0;
ctx->len = 0;
ctx->hash[0] = 0x6a09e667;
ctx->hash[1] = 0xbb67ae85;
ctx->hash[2] = 0x3c6ef372;
ctx->hash[3] = 0xa54ff53a;
ctx->hash[4] = 0x510e527f;
ctx->hash[5] = 0x9b05688c;
ctx->hash[6] = 0x1f83d9ab;
ctx->hash[7] = 0x5be0cd19;
}
} /* sha256_init */ /* -------------------------------------------------------------------------- */
void sha256_hash(sha256_context *ctx, const void *data, size_t len)
{
register size_t i;
const uint8_t *bytes = (const uint8_t *)data; if ( (ctx != NULL) && (bytes != NULL) )
for (i = 0; i < len; i++) {
ctx->buf[ctx->len] = bytes[i];
ctx->len++;
if (ctx->len == sizeof(ctx->buf) ) {
_hash(ctx);
_addbits(ctx, sizeof(ctx->buf) * 8);
ctx->len = 0;
}
}
} /* sha256_hash */ /* -------------------------------------------------------------------------- */
void sha256_done(sha256_context *ctx, uint8_t *hash)
{
register uint32_t i, j; if ( ctx != NULL ) {
j = ctx->len % sizeof(ctx->buf);
ctx->buf[j] = 0x80;
for (i = j + 1; i < sizeof(ctx->buf); i++)
ctx->buf[i] = 0x00; if ( ctx->len > 55 ) {
_hash(ctx);
for (j = 0; j < sizeof(ctx->buf); j++)
ctx->buf[j] = 0x00;
} _addbits(ctx, ctx->len * 8);
ctx->buf[63] = _shb(ctx->bits[0], 0);
ctx->buf[62] = _shb(ctx->bits[0], 8);
ctx->buf[61] = _shb(ctx->bits[0], 16);
ctx->buf[60] = _shb(ctx->bits[0], 24);
ctx->buf[59] = _shb(ctx->bits[1], 0);
ctx->buf[58] = _shb(ctx->bits[1], 8);
ctx->buf[57] = _shb(ctx->bits[1], 16);
ctx->buf[56] = _shb(ctx->bits[1], 24);
_hash(ctx); if ( hash != NULL )
for (i = 0, j = 24; i < 4; i++, j -= 8) {
hash[i ] = _shb(ctx->hash[0], j);
hash[i + 4] = _shb(ctx->hash[1], j);
hash[i + 8] = _shb(ctx->hash[2], j);
hash[i + 12] = _shb(ctx->hash[3], j);
hash[i + 16] = _shb(ctx->hash[4], j);
hash[i + 20] = _shb(ctx->hash[5], j);
hash[i + 24] = _shb(ctx->hash[6], j);
hash[i + 28] = _shb(ctx->hash[7], j);
}
}
} /* sha256_done */ /* -------------------------------------------------------------------------- */
void sha256(const void *data, size_t len, uint8_t *hash)
{
sha256_context ctx; sha256_init(&ctx);
sha256_hash(&ctx, data, len);
sha256_done(&ctx, hash);
} /* sha256 */ } /*********************************************************************************/ #include<iostream>
#include<algorithm>
#include<windows.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<time.h>
#include<stdio.h>
using namespace std;
class Time {
private:
int month;
int day;
int houor;
int minute;
public:
Time();
Time(int m, int d, int h, int mi);
int get_month();
int get_day();
int get_houor();
int get_minute();
void show();
bool operator<(const Time &t);
bool check();
};
Time::Time() {
;
}
Time::Time(int m, int d, int h, int mi) {
month = m;
day = d;
houor = h;
minute = mi;
}
int Time::get_month() {
return month;
}
int Time::get_day(){
return day;
}
void Time::show() {
printf("%02d月%02d日 %02d:%02d ", month, day, houor, minute);
}
bool Time::operator<(const Time &t) {
if (month < t.month)
return true;
else if (month==t.month && day< t.day)
return true;
else if (month==t.month&& day==t.day && houor < t.houor)
return true;
else if (month==t.month && day==t.day&& houor==t.houor && minute < t.minute)
return true;
else
return false;
}
bool Time::check(){
if(!(month>=0 && month<=12 && day>=1 && day<=31 && houor>=0 && houor<=24 && minute>=0 && minute<=60))
return false;
return true;
}
class Passenger {
private:
string name;
string passport;
string country;
string tel_number;
public:
Passenger();
Passenger(string n, string p, string c, string t);
string get_passport();
void Delete();
void set(string n, string p, string c, string t);
void show();
}*TP;
int Count;
Passenger::Passenger() {
;
}
Passenger::Passenger(string n, string p, string c, string t) {
name = n;
passport = p;
country = t;
tel_number = t;
}
string Passenger::get_passport() {
return passport;
}
void Passenger::Delete() {
this->name = " ";
this->passport = " ";
this->country = " ";
this->tel_number = " ";
}
void Passenger::set(string n, string p, string c, string t) {
name = n;
passport = p;
country = t;
tel_number = t;
} void Passenger::show() {
cout << name << " " << passport << " " << country << " " << tel_number << endl;
} struct user_data
{
string ID;
int Role;
int i;
};
class User {
private:
user_data *u;
int length;
int number;
public:
User(int length=100,int number=0){
u=new user_data[length];
this->number=number;
}
void add(string ID,int role,int i){
u[number].ID=ID;
u[number].Role=role;
u[number].i=i;
number++;
}
int change_i(string s){
for(int i=0;i<number;i++){
if(u[i].ID==s){
u[i].i=u[i].i-1;
}
}
}
user_data &get(string s){
int flag=0;
for(int i=0;i<number;i++){
if(u[i].ID==s){
flag=1;
return u[i];
}
}
if(flag==0){
cout<<"用户名错误"<<endl;
exit(0);
}
}
}U; class Flight {
private:
string flight_number;
string type;
string origin_place;
string dest_place;
Time start_time;
Time end_time;
int price;
char S[20][20];
Passenger P[20][20];
int seat;
int x;
int y;
int a_seat;
public:
Flight();
Flight(string f, string t, string o, string d, Time start, Time end, int p, int x, int y, int a = 0);
void set(string f, string t, string o, string d, Time start, Time end, int p, int x, int y, int a = 0);
string get_flight_number();
string get_origin_place();
string get_dest_place();
Time get_start_time();
bool book(Passenger p);
bool book(Passenger p, int x1, int y1);
bool cancel(string s);
void show();
void show_seat();
void show_passenger();
};
Flight::Flight() {
;
}
Flight::Flight(string f, string t, string o, string d, Time start, Time end, int p, int x,int y, int a ) {
this->flight_number = f;
this->origin_place = o;
this->dest_place = d;
this->start_time = start;
this->end_time = end;
this->price = p;
this->type = t;
this->x = x;
this->y = y;
this->a_seat = 0;
this->seat = x * y;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++)
S[i][j] = '0';
}
}
void Flight::set(string f, string t, string o, string d, Time start, Time end, int p, int x,int y, int a) {
this->flight_number = f;
this->origin_place = o;
this->dest_place = d;
this->start_time = start;
this->end_time = end;
this->price = p;
this->type = t;
this->x = x;
this->y = y;
this->a_seat = 0;
this->seat = x * y;
for (int i = 0; i < this->x; i++) {
for (int j = 0; j < this->y; j++)
S[i][j] = '1';
}
}
string Flight::get_flight_number() {
return flight_number;
}
string Flight::get_origin_place() {
return origin_place;
}
string Flight::get_dest_place(){
return dest_place;
}
Time Flight::get_start_time(){
return start_time;
}
bool Flight::book(Passenger p) {
if (a_seat == seat)
return false;
srand((unsigned)time(NULL));
int x1 = rand() % x;
int y1 = rand() % y;
while (S[x1][y1] != '1') {
x1 = rand() % x;
y1 = rand() % y;
}
P[x1][y1] = p;
//P[x1][y1].show();
S[x1][y1] = '*';
a_seat++;
TP[Count++] = p;
return true;
}
bool Flight::book(Passenger p, int x1, int y1) {
if (a_seat == seat) {
cout << "该航班已没有剩余座位" << endl;
return false;
}
if (S[x1][y1] == '*'){
cout << "该座位已被预订" << endl;
return false;
}
S[x1][y1] = '*';
P[x1][y1] = p;
//P[x1][y1].show();
a_seat++;
TP[Count++] = p;
return true; }
bool Flight::cancel(string s) {
int flag = false;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
if (S[i][j] == '*') {
//cout<<P[i][j].get_passport();
if (P[i][j].get_passport() == s) {
flag = true;
S[i][j] = '1';
P[i][j].Delete();
}
}
}
}
if (flag == false)
cout << "不存在此护照号" << endl;
return flag;
}
void Flight::show() {
printf("%-10s%-30s%-10s%-10s ",flight_number.c_str(),type.c_str(),origin_place.c_str(),dest_place.c_str());
start_time.show();
cout<<" ";
end_time.show();
printf("%10d%10d\n",seat,a_seat);
}
void Flight::show_seat() {
cout << " ";
for (int i = 0; i < y; i++)
printf("%d ",i);
cout << endl;
for (int i = 0; i < x; i++) {
printf("%02d ",i);
for (int j = 0; j < y; j++) {
cout << S[i][j]<<" ";
}
cout << endl;
}
}
void Flight::show_passenger(){
for(int i=0;i<x;i++){
for(int j=0;j<y;j++){
if(S[i][j]=='*')
P[i][j].show();
}
}
}
class Menu {
private:
int length;
int number;
int max_increase;
Flight *F;
public:
Menu(int n = 100, int m = 10);
void Increase();
bool Add(string f, string t, string o, string d, Time start, Time end, int p, int x,int y, int a = 0);
void Delete(string f);
void Query();
void Query(string f);
void Query(string s1, string s2);
void Query(Time t);
void Query(string s1, string s2, Time t);
bool Book(string f,Passenger p);
bool Book(string f, Passenger p, int x1, int y1);
void Refund(string f);
void show_seat(string f);
void show_passenger(string f);
bool cancel(string s1, string s2);
};
Menu::Menu(int n, int m) {
F = new Flight[n];
length = n;
max_increase = m;
number = 0;
}
void Menu::Increase() {
Flight *tF = new Flight[length + max_increase];
for (int i = 0; i < length; i++) {
tF[i] = F[i];
}
delete[]F;
F = tF;
length += max_increase;
}
bool Menu::Add(string f, string t, string o, string d, Time start, Time end, int p, int x,int y, int a) {
if (number + 1 <= length) {
Increase();
}
F[number].set(f,t,o,d,start,end,p,x,y,a);
number = number + 1;
return true;
}
void Menu::Delete(string f) {
for (int i = 0; i <= number; i++) {
if (f == F[i].get_flight_number()) {
for (int j = i; j <= number; j++)
F[j] = F[j + 1];
//delete F[j + 1];
number--;
}
}
}
void Menu::Query() {
printf("%-10s%-30s%-10s%-10s%-20s%-20s%-10s%-10s\n","航班号","飞机类型","出发地","目的地","出发时间","到达时间","载客量","已预定数");
for (int i = 0; i <number; i++) {
F[i].show();
}
}
void Menu::Query(string f) {
bool falg = false;
for (int i = 0; i < number; i++) {
if (F[i].get_flight_number() == f) {
F[i].show();
falg = true;
}
}
if (falg == false)
cout << "无此航班" << endl;
}
void Menu::Query(Time t) {
Time t1(t.get_month(), t.get_day(), 0, 0);
Time t2(t.get_month(), t.get_day() + 1, 0, 0);
bool flag = false;
for (int i = 0; i < number; i++) {
if (t1 < F[i].get_start_time() && F[i].get_start_time() < t2) {
flag = true;
F[i].show();
}
}
if (flag == false)
cout << "无符合条件的航班" << endl;
}
void Menu::Query(string s1, string s2) {
bool flag = false;
for (int i = 0; i < number; i++) {
if (F[i].get_origin_place() == s1 && F[i].get_dest_place() == s2 ) {
F[i].show();
flag = true;
}
}
if (flag == false)
cout << "无符合条件的航班" << endl;
}
void Menu::Query(string s1, string s2, Time t) {
Time t1(t.get_month(), t.get_day(), 0, 0);
Time t2(t.get_month(), t.get_day() + 1, 0, 0);
bool flag = false;
for (int i = 0; i < number; i++) {
if (F[i].get_origin_place() == s1 && F[i].get_dest_place() == s2 && t1 < F[i].get_start_time() && F[i].get_start_time() < t2) {
F[i].show();
flag = true;
}
}
}
bool Menu::Book(string f,Passenger p) {
for (int i = 0; i <= number; i++) {
if (f == F[i].get_flight_number()) {
bool J = F[i].book(p);
if (J == false)
return false;
else
return true;
}
}
}
bool Menu::Book(string f, Passenger p, int x1, int y1) {
for (int i = 0; i <= number; i++) {
if (f == F[i].get_flight_number()) {
bool J = F[i].book(p,x1,y1);
if (J == false)
return false;
else
return true;
}
}
}
void Menu::Refund(string f) {
bool flag = false;
for (int i = 0; i < number; i++) {
if (f == F[i].get_flight_number()) {
flag == true;
for (int j = i; j < number-1; j++) {
F[j] = F[j + 1];
}
}
}
number--;
if (flag == false) {
cout << "无此航班" << endl;
}
}
void Menu::show_seat(string f) {
for (int i = 0; i <number; i++) {
if (f == F[i].get_flight_number())
F[i].show_seat();
}
}
bool Menu::cancel(string s1, string s2) {
bool flag = false;
for (int i = 0; i < number; i++) {
if (s1 == F[i].get_flight_number()) {
flag = true;
if (F[i].cancel(s2) == false)
return false;
}
}
if (flag == false) {
cout << "无此航班";
}
return flag;
}
void Menu::show_passenger(string f){
for(int i=0;i<number;i++){
if(f==F[i].get_flight_number()){
F[i].show_passenger();
}
}
}
class Check{
public:
bool time(Time t){
return t.check();
}
bool time(Time t1,Time t2){
if(t1<t2)
return true;
else
return false;
}
bool tel_number(string s){
int len=s.length();
for(int i=0;i<len;i++)
if(!s[i]>='0' && s[i]<='9')
return false;
return true;
}
};
/****************************************************************************************************/
Menu M;
Check C;
void Init() {
FILE *P;
if ((P = fopen("data.txt", "r+")) == NULL) {
cout << "Error" << endl;
exit(0);
}
char f[100];
char t[100];
char o[100];
char d[100];
Time start;
Time end;
int p;
int x;
int y;
int a;
int m1, d1, h1, mi1;
int m2, d2, h2, mi2;
while (fscanf(P, "%s%s%s%s%d%d%d%d%d%d%d%d%d%d%d%d", f, t, o, d, &m1, &d1, &h1, &mi1, &m2, &d2, &h2, &mi2, &p, &x,&y,&a) != EOF) {
M.Add(f, t, o, d, Time(m1, d1, h1, mi1), Time(m2, d2, h2, mi2), p, x,y,a);
}
//M.Query();
}
void Init2(){
FILE *P;
TP=new Passenger[10000];
Count=0;
if((P=fopen("Passenger.txt","r+"))==NULL){
cout<<"error"<<endl;
exit(0);
}
char n[100];
char p[100];
char c[100];
char t[100];
while(fscanf(P,"%s%s%s%s",n,p,c,t)!=EOF){
M.Book("KN5838",Passenger(n,p,c,t));
}
}
void p_query(){
for(int i=0;i<Count;i++)
TP[i].show();
}
void p_query(string s){
bool flag=false;
for(int i=0;i<Count;i++){
if(s==TP[i].get_passport()){
TP[i].show();
flag=true;
}
}
if(flag==false)
cout<<"无此证件号"<<endl;
} bool enroll(){
FILE *P;
srand((unsigned)time(NULL));
char s1[100],s2[100];
uint8_t hash[SHA256_BYTES];
uint8_t hash1[SHA256_BYTES];
size_t i, j;
int judge;
cout<<"1.管理员注册"<<endl;
cout<<"2.普通用户注册:"<<endl;
cin>>judge;
cout<<"输入用户名:";
cin>>s1;
cout<<"输入密码:";
cin>>s2;
// judge=rand()%2;
if(judge==2){
U.add(s1,judge,0);
if((P=fopen("ID1.txt","r+"))==NULL){
cout<<"can not open ID1.txt"<<endl;
return false;
}
char *salt=new char[20];
for(int i=0;i<16;i++)
salt[i]=33+rand()%95;
salt[16]='\0';
int l1=strlen(s2);
int t=l1+16;
for(int i=l1;i<t;i++)
s2[i]=salt[i-l1];
s2[t]='\0';
//for(int i=0;i<strlen(s2);i++)
// cout<<s2[i];
//cout<<endl;
sha256(s2,strlen(s2),hash);
//for(j=0;j<SHA256_BYTES;j++)
// printf("%0x",hash[j]);
fprintf(P,"%s %s\n",s1,salt);
for(j=0;j<SHA256_BYTES;j++)
fprintf(P,"%x ",hash[j]);
fprintf(P,"\n");
fclose(P);
}
else if(judge==1){
int i=1000;
U.add(s1,judge,i);
if((P=fopen("ID2.txt","r+"))==NULL){
cout<<"can not open ID2.txt"<<endl;
exit(0);
}
fprintf(P,"%s\n",s1);
for(i=1;i<=1001;i++){
if(i==1){
sha256(s2,strlen(s2),hash);
// for(j=0;j<SHA256_BYTES;j++)
// printf("%x",hash[j]);
cout<<endl;
}
else{
for(j=0;j<SHA256_BYTES;j++)
hash1[j]=hash[j];
sha256(hash1,SHA256_BYTES,hash);
}
}
for(j=0;j<SHA256_BYTES;j++){
fprintf(P,"%x ",hash[j]); }
// for(j=0;j<SHA256_BYTES;j++)
// printf("%x",hash[j]);
//cout<<endl;
fclose(P);
}
return true;
}
bool land1(){
FILE *P;
if((P=fopen("ID1.txt","r"))==NULL){
cout<<"can not open ID1.txt"<<endl;
return false;
}
uint8_t hash[SHA256_BYTES];
uint8_t hash1[SHA256_BYTES];
size_t j;
char s[100],salt[100];
cout<<"输入用户名:";
char s1[100],s2[100];
cin>>s1;
cout<<"输入密码:";
cin>>s2;
while(fscanf(P,"%s%s",s,salt)!=EOF){
if(strcmp(s,s1)==0){
for(j=0;j<SHA256_BYTES;j++)
fscanf(P,"%x",&hash[j]);
break;
}
}
int l1=strlen(s2);
int t=l1+16;
for(int i=l1;i<t;i++)
s2[i]=salt[i-l1];
s2[t]='\0';
// for(j=0;j<strlen(s2);j++)
// cout<<s2[j];
//cout<<endl;
//for(j=0;j<SHA256_BYTES;j++)
// printf("%0x",hash[j]);
//cout<<endl;
sha256(s2,strlen(s2),hash1);
//for(j=0;j<SHA256_BYTES;j++)
// printf("%0x",hash1[j]);
for(j=0;j<SHA256_BYTES;j++){
if(hash[j]!=hash1[j])
return false;
}
cout<<"登陆成功"<<endl;
return true;
}
bool judge(uint8_t h1[],uint8_t h2[]){
uint8_t h[SHA256_BYTES];
sha256(h1,SHA256_BYTES,h);
size_t j;
for(j=0;j<SHA256_BYTES;j++){
if(h[j]!=h2[j])
return false;
}
return true;
}
bool land2(){
char s1[100],s2[100];
cout<<"请输入用户名:";
cin>>s1;
cout<<"请输入密码:";
cin>>s2;
FILE *P;
user_data u=U.get(s1);
char s[100];
int i=u.i;
uint8_t hash[SHA256_BYTES];
uint8_t hash1[SHA256_BYTES];
uint8_t thash[SHA256_BYTES];
size_t j;
if((P=fopen("ID2.txt","r+"))==NULL){
cout<<"error"<<endl;
return false;
}
while(fscanf(P,"%s",s)!=EOF){
if(strcmp(s1,s)==0){
for(j=0;j<SHA256_BYTES;j++){
fscanf(P,"%x",&thash[j]);
}
break;
}
}
fclose(P);
//for(j=0;j<SHA256_BYTES;j++)
// printf("%x",thash[j]);
//cout<<endl;
for(int k=1;k<=i;k++){
if(k==1){
sha256(s2,strlen(s2),hash);
}
else{
for(j=0;j<SHA256_BYTES;j++)
hash1[j]=hash[j];
sha256(hash1,SHA256_BYTES,hash);
}
}
/*for(j=0;j<SHA256_BYTES;j++){
if(thash[j]!=hash[j])
return false;
}*/
if(judge(hash,thash)==false)
return false;
U.change_i(s1);
for(j=0;j<SHA256_BYTES;j++)
fprintf(P,"%0x",hash[j]);
cout<<"登陆成功"<<endl;
return true;
}
void Operation() {
int judge,Role,operation;
cout<<"请选择 1.注册 2.登陆"<<endl;
while(cin>>judge){
if(judge==1){
if(enroll()==true){
cout<<"注册成功!"<<endl;
}
else{
cout<<"注册失败!"<<endl;
continue;
}
}
else if(judge==2){
cout<<"请选择 1.管理员 2.用户"<<endl;
cin>>Role;
if(Role==1){
if(land2()==true)
break;
else{
cout<<"登陆失败,请重新登陆"<<endl;
continue;
}
}
else if(Role==2){
if(land1()==true)
break;
else{
cout<<"登陆失败,请重新登陆"<<endl;
continue;
}
}
break;
}
else{
cout<<"输入不合法"<<endl;
}
}
cout<<"**************************************************************************************"<< endl;
cout<<"** **"<<endl;
cout<<"** 欢迎进入航班管理系统 **"<< endl;
cout<<"** **"<<endl;
cout<<"**************************************************************************************"<< endl;
int way;
if (Role == 1) {
cout << "请选择操作" << endl;
cout << "0.退出"<<endl;
cout << "1.查询航班信息" << endl;
cout << "2.预约航班" << endl;
cout << "3.取消航班" << endl;
cout << "4.修改航班信息" << endl;
cout << "5.查询旅客信息" << endl;
}
else if (Role == 2) {
cout << "请选择操作" << endl;
cout << "0.退出" << endl;
cout << "1.查询航班信息" << endl;
cout << "2.预约航班" << endl;
cout << "3.取消航班" << endl;
}
else {
cout << "输入不合法" << endl;
exit(0);
}
while (cin >> operation) {
if (operation == 0)
break;
else if (operation == 1) {
int next = 0;
cout << "请选择" << endl;
cout << "1.查询所有航班信息" << endl;
cout << "2.输入航班号查询单个航班信息" << endl;
cout << "3.输入出发地和目的地查询航班信息" << endl;
cout << "4.输入出发时间查询航班信息" << endl;
cout << "5.输入出发地目的地和出发时间查询航班信息" << endl;
cin >> next;
if(next==1){
M.Query();
continue;
}
else if (next == 2) {
string s;
cout << "输入航班号" << endl;
cin >> s;
M.Query(s);
continue;
}
else if (next == 3) {
string s1, s2;
cout << "输入出发地和目的地" << endl;
cin >> s1 >> s2;
M.Query(s1, s2);
continue;
}
else if (next == 4) {
int m, d;
cout << "输入出发时间" << endl;
cin >> m >> d;
M.Query(Time(m, d, 0, 0));
continue;
}
else if (next == 5) {
string s1, s2;
int m, d;
cout << "输入出发地、目的地、出发时间" << endl;
cin >> s1 >> s2;
cin >> m >> d;
M.Query(s1, s2, Time(m, d, 0, d));
continue;
}
}
else if (operation == 2) {
string s;
string s1, s2, s3, s4;
int i;
bool flag;
cout << "输入航班号" << endl;
cin >> s;
cout << "请输入个人信息" << endl;
cout << "请输入您的名字:";
cin >> s1;
cout << endl;
cout << "请输入您的护照号:";
cin >> s2;
cout << endl;
cout << "请输入您的国籍:";
cin >> s3;
cout << endl;
cout << "请输入您的电话号码:";
cin >> s4;
while(C.tel_number(s4)==false){
cout<<"电话号码格式错误,请重新输入"<<endl;
cin>>s4;
}
cout << endl;
//Passenger p(s1, s2, s3, s4);
cout << "是否选择座位(1.是 2.否)" << endl;
cin >> i;
if (i == 1) {
M.show_seat(s);
int x, y;
cout << "请输入座位号(行坐标+列坐标)" << endl;
cin >> x >> y;
flag=M.Book(s,Passenger(s1,s2,s3,s4), x, y);
while (flag == false){
cout<<"订票失败"<<endl;
cout<<"请重新选择座位:";
cin>>x>>y;
flag=M.Book(s,Passenger(s1,s2,s3,s4),x,y);
}
cout<<"订票成功"<<endl;
M.show_seat(s);
}
else {
flag = M.Book(s, Passenger(s1,s2,s3,s4));
if (flag == false)
cout << "订票失败" << endl;
else
cout << "订票成功" << endl;
}
}
else if (operation == 3) {
string s1, s2;
cout << "请输入需要取消的航班号 和 你的护照号" << endl;
cin >> s1 >> s2;
bool flag=M.cancel(s1, s2);
if (flag == false)
cout << "取消航班失败" << endl;
else{
cout<<"操作成功"<<endl;
M.show_seat(s1);
}
}
else if(operation==4){ if(Role==2){
cout<<"您没有此权限"<<endl;
continue;
}
else{
int next;
cout<<"请选择"<<endl;
cout<<"1.增加航班"<<endl;
cout<<"2.删除航班"<<endl;
cin>>next;
if(next==1){
string s1;
cout<<"需要增加的航班信息"<<endl;
char f[100];
char t[100];
char o[100];
char d[100];
int p;
int x;
int y;
int a;
int m1,d1,h1,mi1;
int m2,d2,h2,mi2;
cout<<"航班号:";
cin>>f;
cout<<"飞机类型:";
cin>>t;
cout<<"出发地:";
cin>>o;
cout<<"目的地:";
cin>>d;
int flag=0;
while(flag==0){
cout<<"出发时间:";
cin>>m1>>d1>>h1>>mi1;
while(C.time(Time(m1,d1,h1,mi1))==false){
cout<<endl;
cout<<"时间不合法,请重新输入:";
cin>>m1>>d1>>h1>>mi1;
}
cout<<"到达时间:";
cin>>m2>>d2>>h2>>mi2;
while(C.time(Time(m2,d2,h2,mi2))==false){
cout<<endl;
cout<<"时间不合法,请重新输入:";
cin>>m2>>d2>>h2>>mi2;
}
if(C.time(Time(m1,d1,h1,mi1),Time(m2,d2,h2,mi2))==false){
cout<<"出发时间比到达时间晚,请重新输入"<<endl;
}
else
flag=1;
}
cout<<"价格:";
cin>>p;
cout<<"机舱行数 列数:";
cin>>x>>y;
if(M.Add(f, t, o, d, Time(m1, d1, h1, mi1), Time(m2, d2, h2, mi2), p, x,y,0)==true){
M.Query();
}
else{
cout<<"添加失败"<<endl;
}
}
else{
string number;
cout<<"需要删除的机舱号:";
cin>>number;
M.Delete(number);
M.Query();
}
}
}
else if(operation==5){
if(Role==2){
cout<<"您没有此权限:"<<endl;
continue;
}
else{
int next;
cout<<"请选择:"<<endl;
cout<<"1.查询所有乘客信息:"<<endl;
cout<<"2.查询某个航班乘客信息:"<<endl;
cout<<"3.查询单个乘客信息:"<<endl;
cin>>next;
if(next==1)
p_query();
else if(next==2){
string s;
cout<<"输入航班号"<<endl;
cin>>s;
M.show_passenger(s);
}
else if(next==3){
string s;
cout<<"输入所要查询乘客额护照号:";
cin>>s;
p_query(s);
}
}
}
}
}
int main()
{
Init();
Init2();
Operation();
return 0;
}

  sha256.h

/*
* SHA-256 implementation, Mark 2
*
* Copyright (c) 2010,2014 Ilya O. Levin, http://www.literatecode.com
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef SHA256_H_
#define SHA256_H_ #include <stddef.h>
#ifdef _MSC_VER
#ifndef uint8_t
typedef unsigned __int8 uint8_t;
#endif
#ifndef uint32_t
typedef unsigned __int32 uint32_t;
#endif
#else
#include <stdint.h>
#endif #define SHA256_BYTES 32 #ifdef __cplusplus
extern "C"
{
#endif typedef struct {
uint8_t buf[];
uint32_t hash[];
uint32_t bits[];
uint32_t len;
} sha256_context; void sha256_init(sha256_context *ctx);
void sha256_hash(sha256_context *ctx, const void *data, size_t len);
void sha256_done(sha256_context *ctx, uint8_t *hash); void sha256(const void *data, size_t len, uint8_t *hash); #ifdef __cplusplus
}
#endif #endif

C++航空系统的更多相关文章

  1. 第1章 Linux系统简介

    第1节 UNIX发展历史和发行版本 1. UNIX与Linux发展史 1.1 UNIX发展历史 (1)1965年,美国麻省理工学院(MIT).通用电气公司(GE)及AT&T的贝尔实验室联合开发 ...

  2. Linux基础学习(1)--Linux系统简介

    第一章——Linux系统简介 1.UNIX和Linux发展史: 1.1 unix发展史: (1)1965年,美国麻省理工学院(MIT).通用电气公司(GE)及AT&T的贝尔实验室联合开发Mul ...

  3. 现代工程仿真CAE技术介绍

    随着现代科学技术的发展,人们正在不断建造更为快速的交通工具.更大规模的建筑物.更大跨度的桥梁.更大功率的发电机组和更为精密的机械设备.这一切都要求工程师在设计阶段就能精确地预测出产品和工程的技术性能, ...

  4. linux学习笔记1

    2016年09月25日 unix与linux发展史 unix是linux之父,学习linux后能容易上手unix. linux是源码开放的unix,由一位芬兰大学生李纳斯在网络上发起,和后来众多爱好者 ...

  5. 2012高校GIS论坛

    江苏省会议中心 南京·钟山宾馆(2012年4月21-22日) 以"突破与提升"为主题的"2012高校GIS论坛"将于4月在南京举行,由南京大学和工程中心共同承办 ...

  6. Linux入门基础知识

    注:内容系兄弟连Linux教程(百度传课:史上最牛的Linux视频教程)的学习笔记. Linux入门基础知识 1. Unix和Linux发展历史 二者就像父子关系,当然Unix是老爹.1965年,MI ...

  7. 存储那些事儿(一):异构虚拟化一种实现SMIS

    1. 背景 企业存储是企业信息系统管理很重要的组成部分.企业存储包含了大量的数据,供大量人使用.对于航空系统和金融系统来说,信息存储就更加重要了. 作为企业信息存储,扩展性是非常重要的,因为现在企业对 ...

  8. C# 一维码生成

    概念 一维条码即指条码条和空的排列规则,常用的一维码的码制包括:EAN码.39码.交叉25码.UPC码.128码.93码,ISBN码,及Codabar(库德巴码)等. 条形码起源于 20 世纪 40 ...

  9. Linux入门之简介

    1.啥是linux? Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和Unix的多用户.多任务.支持多线程和多CPU的操作系统. 它能运行主要的Unix工具软件.应用程序 ...

随机推荐

  1. redis 简介,安装与部署

    NOSQL简介 NoSQL,泛指非关系型的数据库,NoSQL数据库的四大分类: 键值(Key-Value)存储数据库:这一类数据库主要会使用到一个哈希表,这个表中有一个特定的键和一个指针指向特定的数据 ...

  2. git add和git commit

    git命令使用:提交前可指定要提交哪些文件,然后使用git commit来提交 样例: git status 输出: Changes to be committed: modified:   app/ ...

  3. Java09-java语法基础(八)java中的方法

    Java09-java语法基础(八)java中的方法 一.方法(函数/过程):是一个程序块,可以完成某种功能 1.java中方法的定义格式 [访问控制修饰符]  返回值类型  方法名(参数列表){ 方 ...

  4. Java02-java语法基础(一)数据类型

    Java02-java语法基础(一)数据类型 一.语法基础 语句:以分号(;)结束 System.out.println(“Hello World !”); 语句块:用一组花括号({})括起来 { … ...

  5. SqlServer中的数据库分类

    1.系统数据库(中央管理机构):用来管理用户创建用户数据的数据库. 系统数据库中包含如下数据库: (1)master:记录了sqlserver中所有系统级别的信息,包括所有的登录账户.系统配置,还有其 ...

  6. mysql 添加外键

    create table class( cid tinyint unsigned primary key auto_increment, caption varchar(15) not null)en ...

  7. 免费证书https://lamp.sh/ssl.html

    https(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的 http 通道,简单讲是 http 的安全版.即 ht ...

  8. SQL注入漏洞的原理

    在平常生活中,我们登陆某网页,常常需要输入用户名和密码,点击登陆,即可登陆成功. 对于黑客来说,不需要用户名和密码,只输入 admin '— 也可以登陆成功. 黑客利用的这种漏洞就是SQL Injec ...

  9. Numpy 学习 array np.where lexsort 切片 按行按列求平均mean

    array 的创建可以通过list给 array print出来像一个表格,可以按行按列来观察. 原来是一个list相当于一行 np.where用于寻找一个condition下的坐标,返回的是一个2个 ...

  10. 把一行数字(readline)读进List并以科学计数法输出(write)到文件

    主要过程是读取的时候是一行字符串,需要Strip去除空格等,然后split变成一个List. 注意这时候数据结构是List但是每一个元素是Str性质的. 所以需要map(float,List)  把这 ...