几个有意思的小程序?

· · 个人记录

这个合集是作者玩Hacknet入迷的产物,不喜勿喷……

最开始:一个头文件

#ifndef coordinate_system.h
#define coordinate_system.h

#include<iostream>  
#include<windows.h>  
#include<conio.h>  
#include<time.h>  
#include<string>  
#include<ctime>
#include<cstdlib>

typedef struct Frame  
{  
    COORD position[2];  
    int flag;  
}Frame;

void SetPos(COORD a)// set cursor   
{  
    HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);  
    SetConsoleCursorPosition(out, a);  
}  

void SetPos(int i, int j)// set cursor  
{  
    COORD pos={i, j};  
    SetPos(pos);  
}  

void HideCursor()  
{  
    CONSOLE_CURSOR_INFO cursor_info = {1, 0};   
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);  
}  

//把第y行,[x1, x2) 之间的坐标填充为 ch  
void drawRow(int y, int x1, int x2, char ch)  
{  
    SetPos(x1,y);  
    for(int i = 0; i <= (x2-x1); i++)  
        std::cout<<ch;  
}  

//在a, b 纵坐标相同的前提下,把坐标 [a, b] 之间填充为 ch  
void drawRow(COORD a, COORD b, char ch)  
{  
    if(a.Y == b.Y)  
        drawRow(a.Y, a.X, b.X, ch);  
    else  
    {  
        SetPos(0, 25);  
        std::cout<<"error code 01:无法填充行,因为两个坐标的纵坐标(x)不相等";  
        system("pause");  
    }  
}  

//把第x列,[y1, y2] 之间的坐标填充为 ch  
void drawCol(int x, int y1, int y2, char ch)  
{  
    int y=y1;  
    while(y!=y2+1)  
    {  
        SetPos(x, y);  
        std::cout<<ch;  
        y++;  
    }  
}  

//在a, b 横坐标相同的前提下,把坐标 [a, b] 之间填充为 ch  
void drawCol(COORD a, COORD b, char ch)  
{  
    if(a.X == b.X)  
        drawCol(a.X, a.Y, b.Y, ch);  
    else  
    {  
        SetPos(0, 25);  
        std::cout<<"error code 02:无法填充列,因为两个坐标的横坐标(y)不相等";  
        system("pause");  
    }  
}  

//左上角坐标、右下角坐标、用row填充行、用col填充列  
void drawFrame(COORD a, COORD  b, char row, char col)  
{  
    drawRow(a.Y, a.X+1, b.X-1, row);  
    drawRow(b.Y, a.X+1, b.X-1, row);  
    drawCol(a.X, a.Y+1, b.Y-1, col);  
    drawCol(b.X, a.Y+1, b.Y-1, col);  
}  

void drawFrame(int x1, int y1, int x2, int y2, char row, char col)  
{  
    COORD a={x1, y1};  
    COORD b={x2, y2};  
    drawFrame(a, b, row, col);  
}  

void drawFrame(Frame frame, char row, char col) //画从点(a,b)到点(c,d)的框架 
{  
    COORD a = frame.position[0];  
    COORD b = frame.position[1];  
    drawFrame(a, b, row, col);  
}
#endif

第一个:假的SSH解码器

#include"coordinate_system.h"
#include<cstdio>
#include<iostream>  
#include<windows.h>  
#include<conio.h>  
#include<time.h>  
#include<string>  
#include<ctime>
#include<cstdlib>
using namespace std;
bool vis[80][25];
int main()
{
    srand((int)time(0));    //随机种子  
    HideCursor();   //隐藏光标  
//  drawFrame(0, 0, 48, 24, '=', '|');//    draw map frame;  
//    drawFrame(49, 0, 79, 22, '-', '|');//        draw output frame  
//    drawFrame(49, 9, 79, 22, '-', '|');//   draw operate frame  
//    drawFrame(49, 22, 79, 24, '-', '|');//  draw other message frame
    int a=11,b=99,cnt=0;
    int x=(rand()%(a-b))+a;
    for(int t=1;t<=500;t++)
    {
        if(cnt>=500)break;
        if(t<=60)
        {
            for(int i=0;i<=79;i+=4)//控制列 
            {
                for(int j=0;j<=24;j++)//控制行 
                {
                    SetPos(i,j);
                    x=(rand()%(a-b))+a;
                    printf("%d",x);
                }
            }
        }
        else
        {
            for(int i=0;i<=79;i+=4)
            {
                for(int j=0;j<=24;j++)
                {
                    SetPos(i,j);
                    x=(rand()%(a-b))+a;
                    if(vis[i][j]==1)continue;
                    if(x<=13)printf("00"),vis[i][j]=1,cnt++;
                    else printf("%d",x);
                }
            }
        }
    }
    memset(vis,0,sizeof(vis));
    system("cls");
    drawFrame(28, 10, 51, 16, '-', '|');
    SetPos(35,13);//此函数前一个参数是列数,后一个参数是行数 
    printf("端口已打开!");
    for(int i=11;i<=21;i++)
    {
        SetPos(0,i);
        printf("\n");
    }
    return 0;
}

第二个:假的Porthack

#include"coordinate_system.h"
#include<cstdio>
#include<iostream>  
#include<windows.h>  
#include<conio.h>  
#include<time.h>  
#include<string>  
#include<ctime>
#include<cstdlib>
using namespace std;
bool vis[80][25];
int main()
{
    srand((int)time(0));    //随机种子  
    HideCursor();   //隐藏光标  
//  drawFrame(0, 0, 48, 24, '=', '|');//    draw map frame;  
//    drawFrame(49, 0, 79, 22, '-', '|');//        draw output frame  
//    drawFrame(49, 9, 79, 22, '-', '|');//   draw operate frame  
    drawFrame(28, 10, 51, 15, '-', '|');
    int a=111,b=99999,cnt=35;
    int x=(rand()%(a-b))+a;
    for(int t=1;t<=600;t++)
    {
        for(int i=0;i<=24;i++)//控制行
        {
            SetPos(0,i);
            cout<<"       ";SetPos(0,i);
            x=(rand()%(a-b))+a;
            if(x<=5000)
            {
                x=(x%3)+4;
                int y=(rand()%(122-97))+97;
                for(int j=1;j<=x;j++)
                printf("%c",y),y=(rand()%(122-97))+97;
            }
            else printf("%d",x);
            SetPos(73,i);
            cout<<"       ";SetPos(75,i);
            x=(rand()%(a-b))+a;
            if(x<=5000)
            {
                x=(x%3)+4;
                int y=(rand()%(122-97))+97;
                for(int j=1;j<=x;j++)
                printf("%c",y),y=(rand()%(122-97))+97;
            }
            else printf("%d",x);
        }
        for(int i=0;i<=24;i++)
        {
            for(int j=8;j<=68;j+=5)
            {
                if(i>=10&&i<=15&&j>=28&&j<=51)continue;                 
                SetPos(j,i);
                int gg[5]={0};
                for(int k=1;k<=4;k++)
                {
                    gg[k]=rand()%2;
                    printf("%d",gg[k]);
                }
            }
        }
        if(t<=60)continue;
        else
        {
            if(cnt<=44)
            {
                SetPos(cnt,12);
                int kkk=rand()%12;
                if(kkk>=2)continue;
                kkk=rand()%5;
                if(kkk>=2)printf("%c",(rand()%(122-97))+97);
                else printf("%d",rand()%10);
                cnt++;
            }
            else break;
        }
    }
    memset(vis,0,sizeof(vis));
//  system("cls");
    SetPos(35,13);//此函数前一个参数是列数,后一个参数是行数 
    printf("端口已打开!");
    for(int i=11;i<=23;i++)
    {
        SetPos(0,i);
        printf("\n");
    }
    system("pause");
    return 0;
}

第三个:假的FTPsprint

#include"coordinate_system.h"
#include<cstdio>
#include<iostream>  
#include<windows.h>  
#include<conio.h>  
#include<time.h>  
#include<string>  
#include<ctime>
#include<cstdlib>
using namespace std;
bool vis[80][25];
int main()
{
    srand((int)time(0));    //随机种子  
    HideCursor();   //隐藏光标  
//  drawFrame(0, 0, 48, 24, '=', '|');//    draw map frame;  
//    drawFrame(49, 0, 79, 22, '-', '|');//        draw output frame  
//    drawFrame(49, 9, 79, 22, '-', '|');//   draw operate frame  
//    drawFrame(49, 22, 79, 24, '-', '|');//  draw other message frame
    int a=11,b=99,cnt=0,aa=6;
    for(int t=1;t<=250;t++)
    {
        if(t%40==0&&aa>1)aa--;
        for(int j=0;j<=79;j++)
        {
            int kk=rand()%3;
            if(kk<2)
            {
                for(int i=0;i<=11;i++)
                SetPos(j,i),printf(" ");
                kk=rand()%aa;
                int fu=rand()%2;
                if(fu==1)kk=-kk;
                SetPos(j,kk+5);
                printf("-");
            }   
        }
        for(int i=0;i<=79;i+=5)//控制列 
        {
            for(int j=12;j<=24;j++)//控制行 
            {
                int kk=rand()%30;
                if(kk==0&&vis[i][j]!=1)
                {
                    SetPos(i,j);
                    vis[i][j]=1;
                    int v=rand()%2,x=rand()%2,y=rand()%2,z=rand()%2;
                    printf("%d%d%d%d",v,x,y,z);
                }
            }
        }
    }
    memset(vis,0,sizeof(vis));
    system("cls");
    drawFrame(28, 10, 51, 16, '-', '|');
    SetPos(35,13);//此函数前一个参数是列数,后一个参数是行数 
    printf("端口已打开!");
    for(int i=11;i<=21;i++)
    {
        SetPos(0,i);
        printf("\n");
    }
    return 0;
}

第四个:假的SMTPoverflow

#include"coordinate_system.h"
#include<cstdio>
#include<iostream>  
#include<windows.h>  
#include<conio.h>  
#include<time.h>  
#include<string>  
#include<ctime>
#include<cstdlib>
using namespace std;
bool vis[80][25];
int ss[80][25];
int main()
{
    srand((int)time(0));    //随机种子  
    HideCursor();   //隐藏光标  
//  drawFrame(0, 0, 48, 24, '=', '|');//    draw map frame;  
//    drawFrame(49, 0, 79, 22, '-', '|');//        draw output frame  
//    drawFrame(49, 9, 79, 22, '-', '|');//   draw operate frame  
//    drawFrame(49, 22, 79, 24, '-', '|');//  draw other message frame
    int a=0,b=9;
    int x=(rand()%(a-b))+a;
    for(int t=1;t<=350;t++)
    {
        if(t==1)
        {
            for(int i=0;i<=79;i+=3)//控制列 
            {
                for(int j=0;j<=24;j++)//控制行 
                {
                    SetPos(i,j);
                    x=(rand()%(a-b))+a;
                    ss[i][j]=x;
                    printf("%d",x);
                }
            }
        }
        int xx=(rand()%(24-0))+0,yy=(rand()%(79-0))+0;
        for(int k=1;k<=10;k++)
        {
            for(int i=1;i<=79;i+=3)
            {
                SetPos(i,xx);
                printf("%d",ss[i-1][xx]);
            }
            ss[81][xx]=(rand()%(a-b))+a;
            for(int i=0;i<=79;i+=3)
            {
                ss[i][xx]=ss[i+1][xx];
            }
        }
        for(int k=1;k<=10;k++)
        {
            for(int i=1;i<=24;i++)
            {
                SetPos(yy,i);
                printf("%d",ss[yy][i-1]);
            }
            ss[yy][25]=(rand()%(a-b))+a;
            for(int i=0;i<=24;i++)
            {
                ss[yy][i]=ss[yy][i+1];
            }
        }
    }
    memset(vis,0,sizeof(vis));
    system("cls");
    drawFrame(28, 10, 51, 16, '-', '|');
    SetPos(35,13);//此函数前一个参数是列数,后一个参数是行数 
    printf("端口已打开!");
    for(int i=11;i<=21;i++)
    {
        SetPos(0,i);
        printf("\n");
    }
    return 0;
}

第五个:假的Decrypt

#include"coordinate_system.h"
#include<cstdio>
#include<iostream>  
#include<windows.h>  
#include<conio.h>  
#include<time.h>  
#include<string>  
#include<ctime>
#include<cstdlib>
using namespace std;
bool vis[80][25];
int ss[80][25];
int main()
{
    srand((int)time(0));    //随机种子  
    HideCursor();   //隐藏光标  
//  drawFrame(0, 0, 48, 24, '=', '|');//    draw map frame;  
//    drawFrame(49, 0, 79, 22, '-', '|');//        draw output frame  
//    drawFrame(49, 9, 79, 22, '-', '|');//   draw operate frame  
//    drawFrame(49, 22, 79, 24, '-', '|');//  draw other message frame
    int a=0,b=9;
    int x=(rand()%(a-b))+a;
    for(int i=0;i<=79;i+=3)//控制列 
    {
        for(int j=0;j<=24;j++)//控制行 
        {
            SetPos(i,j);
            x=(rand()%(a-b))+a;
            ss[i][j]=x;
            printf("%d",x);
        }
    }
    for(int t=1;t<=10;t++)
    {
        int xx=(rand()%(24-0))+0,yy=(rand()%(79-0))+0;
        while((yy)%3)yy=rand()%80;
        int xx1=(rand()%(24-0))+0,yy1=(rand()%(79-0))+0;
        while((yy1)%3)yy1=rand()%80;
        for(int k=1;k<=300;k++)
        {
            for(int i=0;i<=79;i+=3)
            {
                SetPos(i,xx);
                printf("%d",ss[i+3][xx]);
                SetPos(i,xx1);
                printf("%d",ss[i+3][xx1]);
            }
            ss[81][xx]=rand()%10;
            ss[81][xx1]=rand()%10;
            for(int i=0;i<79;i+=3)
            {
                ss[i][xx]=ss[i+3][xx];
                ss[i][xx1]=ss[i+3][xx1];
            }
            for(int i=0;i<=24;i++)
            {
                SetPos(yy,i);
                printf("%d",ss[yy][i+1]);
                SetPos(yy1,i);
                printf("%d",ss[yy1][i+1]);
            }
            ss[yy][25]=rand()%10;
            ss[yy1][25]=rand()%10;
            for(int i=0;i<=24;i++)
            {
                ss[yy][i]=ss[yy][i+1];
                ss[yy1][i]=ss[yy1][i+1];
            }
        }
    }
    memset(vis,0,sizeof(vis));
    system("cls");
    drawFrame(28, 10, 51, 16, '-', '|');
    SetPos(35,13);//此函数前一个参数是列数,后一个参数是行数 
    printf("文档转码成功!");
    for(int i=11;i<=21;i++)
    {
        SetPos(0,i);
        printf("\n");
    }
    return 0;
}

第六个:假的WebServerWrom

#include"coordinate_system.h"
#include<cstdio>
#include<iostream>  
#include<windows.h>  
#include<conio.h>  
#include<time.h>  
#include<string>  
#include<ctime>
#include<cstdlib>
using namespace std;
int cnt;
int ss[25];
int main()
{
    srand((int)time(0));    //随机种子  
    HideCursor();   //隐藏光标  
//  drawFrame(0, 0, 48, 24, '=', '|');//    draw map frame;  
//    drawFrame(49, 0, 79, 22, '-', '|');//        draw output frame  
//    drawFrame(49, 9, 79, 22, '-', '|');//   draw operate frame  
//    drawFrame(49, 22, 79, 24, '-', '|');//  draw other message frame
    int a=0,b=9;
    int x=(rand()%(a-b))+a;
    for(int i=0;i<=24;i++)//控制列 
    {
        ss[i]=rand()%20;
        for(int j=0;j<=ss[i];j++)//控制行 
        SetPos(j,i),printf("-");
    }
    for(int t=1;t<=1000;t++)
    {
//      Sleep(500);
        for(int j=0;j<=24;j++)
        {
            if(ss[j]>=79)continue;
            int xx=rand()%5,yy=rand()%15;
            if(yy>=12)xx*=-1;
            ss[j]+=xx;
            if(ss[j]>=79)cnt++;
            for(int i=0;i<=79;i++)
            SetPos(i,j),printf(" ");
            for(int i=0;i<=ss[j];i++)//控制行 
            SetPos(i,j),printf("-");
        }
        if(cnt>=25)break;
    }
//    memset(vis,0,sizeof(vis));
    system("cls");
    drawFrame(28, 10, 51, 16, '-', '|');
    SetPos(35,13);//此函数前一个参数是列数,后一个参数是行数 
    printf("端口已打开!");
    for(int i=11;i<=21;i++)
    {
        SetPos(0,i);
        printf("\n");
    }
    return 0;
}