版本比较
花费半年做的超级头文件共享
正文
增加 958 行删除 958 行
89 行未改动90919293949495969798406 行未改动全部展开505506507508509509510511512513167 行未改动全部展开6816826836846856856866876886886896906916927 行未改动7007017027037047047057067077087087097107117126 行未改动71972072172272372372472572672714 行未改动74274374474574674774674774874975075153 行未改动805806807808809809810811812813359 行未改动全部展开11731174117511761177117711781179118011811182118311821183118411851186118711881189119011891190119111921193119411951196119711981199119811991200120112021202120312041205120612071207120812091209121012111212121312141215121612161217121812191220122112221223122412231224122512261227122812291229123012311232123312341235123612371238123712381239124012411242124212431244124512468 行未改动12551256125712581259125912601261126212638 行未改动12721273127412751276127612771278127912808 行未改动12891290129112921293129312941295129612978 行未改动13061307130813091310131013111312131313141315131613161317131813191320132113221321132213231324132513261327132813291328132913301331133213331334133513361335133613371338133913401341134213431342134313441345134613471348134913501349135013511352135213531354135513561357135813591360136113601361136213631364136513661367136713681369136913701371137213737 行未改动13811382138313841385138513861387138813891390139013911392139213931394139513961397139713981399140014011401140214031404140514061407140714081409141014111412141314131414141514161417141814191420142014211422142314244 行未改动14291430143114321433143314341435143614361437143814391440144114421442144314441445144614471447144814491450145114521453145414551456145714571458145914601461146214631464146514661466146714681469147058 行未改动152915301531153215331533153415351536153712 行未改动15501551155215531554155415551556155715585 行未改动156415651566156715681568156915701571157234 行未改动1607160816091610161116111612161316141615161616171618161916201620162116221623162416251626162716281629163016301631163216331634163516361637163716381639164016411642164316441645164516461647164816497 行未改动16571658165916601661166116621663166416651666166716681669167016711671167216731674167516761677167816791680168016811682168316844 行未改动16891690169116921693169316941695169516961697169816991700170117021702170317041705170617071708170917091710171117121713171417151716171617171718171917204 行未改动172517261727172817291729173017311731173217331734173517351736173717381739174017411742174217431744174517461747174817491749175017511752175217531754175517561757175817591760176117621762176317641765176613 行未改动1780178117821783178417841785178617871788178917901790179117921793179417951796179717971798179918001801180218031804180418051806180718081809181018111811181218131814181513 行未改动1829183018311832183318331834183518361837183818391840184018411842184318441845184618471847184818491850185111 行未改动18631864186518661867186718681869187018717 行未改动18791880188118821883188318841885188618871888188918901890189118921893189411 行未改动19061907190819091910191019111912191319142 行未改动19171918191919201921192119221923192419257 行未改动193319341935193619371937193819391940194119421943194319441945194619471948194919501950195119521953195422 行未改动19771978197919801981198119821983198419851986198619871988198919901991199119921993199419958 行未改动200420052006200720082008200920102011201210 行未改动202320242025202620272027202820292030203120322033203320342035203620372038203920392040204120422043204420452045204620472047204820492050205120522052205320542055205623 行未改动2080208120822083208420842085208620872088208820892090209120927 行未改动21002101210221032104210421052106210621072108210921102111211221132114211521162116211721182118211921202121212245 行未改动216821692170217121722172217321742175217621772177217821792180218021812182218221832184218521862187218821882189219021902191219221932194219521962197219721982199220022012 行未改动220422052206220722082209220822092210221122112212221322142215221622172218221922182219222022212222222346 行未改动227022712272227322742274227522762277227829 行未改动23082309231023112312231223132314231523164 行未改动23212322232323242325232523262327232823292330233123322333233423352334233523362337233823392339234023412342234223432344234523462346234723482349235023512352235323542355235523562357235823592359236023612361236223632364236523662366236723682369237023692370237123722372237323742375237623762377237823792380238023812382238323832384238523862387238823892389239023912392239312 行未改动240624072408240924102410241124122413241424152416241724172418241924202421242224232423242424252425242624272428242973 行未改动250325042505250625072507250825092509251025112512251325142514251525162517251825192520252025212522252325242525252625272527252825292530253125322533253425352535253625372537253825392540254125422542254325442544254525462547254825482549255025512552255325542555255625562557255825592560256125622562256325642565256625672568256925692570257125722572257325742575257625772577257825792580258125822583258325842585258625872588258925882589259025912592259325942594259525962597259825992600260126012602260326042605260626062607260826082609261026112612261226132614261526152616261726182619262026212621262226232624262526262627262826292629263026312632263226332634263526362637263826392640264026412642264326443 行未改动264826492650265126522652265326542654265526562657265726582659266026612662266326642665266626672667266826692670267126722672267326742675267626772678267826792680268126822681268226832684268526862687268826892689269026912692269226932694269526962696269726982699270047 行未改动274827492750275127522752275327542755275627562757275827592760276127622763276427652765276627672768276827692770277127722773277427752775277627772778277927802781278227832783278427852786278727882789278927902791279227932794279527952796279727982799279928002801280228032804280528062806280728082809281028112812281328142814281528162816281728182819282028212820282128222823282428252826282728282829283028302831283228332833283428352836283728382837283828392840284128422842284328442845284628452846284728482848284928502851285228532854285528552856285728582859285928602861286128622863286428652866286528662867286828692870287028712872287328732874287528762877287828792880288128822883288328842885288628872888288728882889289028912892289328932894289528962896289728982899290034 行未改动2935293629372938293929392940294129422943294429452946294629472948294829492950295129522 行未改动295529562957295829592960295929602961296229632964296529662967296729682969297029714 行未改动2976297729782979298029802981298229832984298529862987298829892989299029912992299323 行未改动301730183019302030213021302230233024302517 行未改动304330443045304630473047304830493050305121 行未改动30733074307530763077307730783079308030816 行未改动308830893090309130923092309330943095309630973098309931003101310231023103310431053106310731083109311031103111311231133114103 行未改动全部展开32183219322032213222322232233224322432253226322732284 行未改动323332343235323632373237323832393240324132413242324332443245324632473248324932503251325132523253325432554 行未改动32603261326232633264326432653266326732685 行未改动327432753276327732783279327832793280328132823283328432843285328632873288266 行未改动全部展开355535563557355835593559356035613562356335643565356635673568356835693570357135723573357335743575357635773578357935803581358235833583358435853586358731 行未改动361936203621362236233623362436253626362713 行未改动364136423643364436453645364636473648364918 行未改动3668366936703671367236723673367436753676367636773678367936809 行未改动36903691369236933694369436953696369736986 行未改动37053706370737083709370937103711371237137 行未改动3721372237233724372537253726372737283729155 行未改动全部展开38853886388738883889388938903891389138923893389438953896389738983898389939003901390239033903390439053905390639073908390925 行未改动393539363937393839393939394039413942394328 行未改动397239733974397539763976397739783979398038 行未改动401940204021402240234023402440254026402730 行未改动405840594060406140624062406340644065406626 行未改动40934094409540964097409740984099410041014101410241034104410541064107410741084109411041114112411341144114411541164117411858 行未改动417741784179418041814181418241834184418541864187418741884189419041914192419341944195419541964197419841997 行未改动420742084209421042114211421242134214421537 行未改动425342544255425642574257425842594260426142624262426342644265426642674268426842694270427142714272427342744275427542764277427842796 行未改动428642874288428942904290429142924293429415 行未改动43104311431243134314431443154316431743184319431943204321432243234324432543264327432843294330432943304331433243334334433543364336433743384339434016 行未改动43574358435943604361436143624363436443644365436643674368436943704370437143724373437443754376437643774378437943804381438243834384438543864386438743884389439043914392439243934394439543964397439843994399440044014402440344044405440644074407440844094410441144114412441344144415441644174417441844194420442144224423442344244425442644274428442944304431443244334433443444354436443744384439443944404441444244434 行未改动4448444944504451445244524453445444554456104 行未改动全部展开456145624563456445654565456645674568456988 行未改动46584659466046614662466246634664466546654666466746684668466946704671467246734674467546764676467746784679468046814682468346834684468546854686468746884689469046904691469246934693469446954696469746984699469947004701470247034704470447054706470747085 行未改动47144715471647174718471847194720472147224723472447254725472647274728472947294730473147324733293 行未改动全部展开502750285029503050315031503250335033503450355036503750385039504050415041504250435044504583 行未改动51295130513151325133513351345135513651375138513951395140514151425143100 行未改动524452455246524752485249524852495250525152515252525352545255525652565257525852585259526052605261526252625263526452645265526652665267526852685269527052705271527252735273527452755275527652775277527852795279528052815281528252835284528552865286528752885289529052915292529352945295529652965297529852985299530053005301530253025303530453045305530653065307530853085309531053105311531253125313531453145315531653165317531853185319532053205321532253225323532453245325532653265327532853295330533053315332533353346 行未改动534153425343534453455345534653475348534953505350535153525352535353545355535653565357535853595360536153625363536453645365536653675368536953705370537153725373537453755375537653775378537953795380538153815382538353845384538553865387538853895390539153925393539353945395539653975398539954005400540154025403540454055405540654075408540954105411541154125413541454155415541654175418541954205421542154225423542454252 行未改动5428542954305431543254325433543454355436543754385439543954405441544254425443544454445445544654465447544854485449545054515451545254535454545554555456545754585459546054605461546254635463546454655466546754685469547054705471547254735474547454755476547754785479548054815482548354835484548554855486548754885489548954905491549254935494549454955496549754982 行未改动55015502550355045505550555065507550855094 行未改动55145515551655175518551855195520552155225522552355245525552555265527552755285529553055315532553355345535553555365537553855392 行未改动55425543554455455546554655475548554955505550555155525552555355545555555655575558555855595560556155625563556455655566556655675568556855695570557155725573557455755576557655775578557955795580558155815582558355845585558555865587558855897 行未改动5597559855995600560156015602560356045605560656065607560856095610561156125613561456155616561656175618561856195620562156225623562356245625562656275628562856295630563156323 行未改动563656375638563956405640564156425643564456455646564656475648564956504 行未改动565556565657565856595659566056615662566313 行未改动56775678567956805681568156825683568456855686568756885689568956905691569256932 行未改动569656975698569957005700570157025703570457055706570757085708570957105711571257135714571457155716571657175718571957205721572257235724572557255726572757285729573057315732573257335734573557365736573757385739574014 行未改动57555756575757585759575957605761576257635764576557665767576857695769577057715772577357745774577557765777577810 行未改动57895790579157925793579357945795579657975798579958005800580158025803580458055806580658075808580858095810581158125813581458155816581758175818581958195820582158225823582458245825582658275828582958305831583258335834583458355836583758385839584058415842584258435844584458455846584758485848584958505851585258535854585558565857585858585859586058615862586358635864586558665867586858695870587058715872587358745 行未改动58805881588258835884588458855886588758885889589058915892589258935894589558966 行未改动590359045905590659075907590859095910591159115912591359135914591559165917591859195920592159225923592359245925592559265927592859295930593159325933593459345935593659365937593859395940594159415942594359445945594659475948594959505950595159525953595459555955595659575958595959605960596159625962596359645965596659675968596959705971597159725973597359745975597659775978597959805981598259835983598459855985598659875988598959905991599259925993599459945995599659965997599859996000600060016002600360049 行未改动60146015601660176018601860196020602160216022602360236024602560266026602760286029603060316032603360346035603560366037603860396040604060416042604360442 行未改动60476048604960506051605160526053605360546055605560566057605760586059606060606061606260626063606460646065606660666067606860686069607060706071607260736073607460756076607660776078607960806081608160826083608460856086608660876088608960906091609260936094609560966096609760986099610029 行未改动61306131613261336134613461356136613761386139614061416142614361436144614561466147614861486149615061516152615361526153615461556156615717 行未改动617561766177617861796179618061816182618261836184618561866186618761886189619014 行未改动620562066207620862096209621062116212621380 行未改动62946295629662976298629862996300630163023 行未改动6306630763086309631063116310631163126313631463155 行未改动6321632263236324632563256326632763286329633063296330633163326333633415 行未改动6350635163526353635463546355635663576358635963596360636163626363636463646365636663676368636763686369637063716372637263736374637563766376637763786379638063796380638163826383638418 行未改动64036404640564066407640764086409641064117 行未改动64196420642164226423642364246425642664276427642864296430643164326432643364346435643619 行未改动6456645764586459646064606461646264636464646464656466646764686468646964706470647164726473647464756475647664776478647964796480648164816482648364846485648664876487648864896490649164916492649364946495649564966497649864996499650065016502650322 行未改动65266527652865296530653065316532653365342 行未改动653765386539654065416541654265436543654465456546654765486548654965506551655265536554655565556556655765576558655965606561656165626563656365646565656665676568656865696570657065716572657365736574657565766577657865776578657965806581658265836582658365846585658665876588658965906591659265926593659465946595659665976598659865996600660066016602660266036604660466056606660766086609660866096610661166126613661466146615661666176617661866196619662066216622662366236624662566256626662766286629662966306631663166326633663466355 行未改动664166426643664466456646664566466647664866496650665166516652665366546655665666576658665966606661666166626663666466646665666666676668666866696670667066716672667366736674667566766677667866796678667966806681668266836684668566866686668766886689668966906691669266936694669366946695669666976698669967006700670167026703670484 行未改动678967906791679267936793679467956796679767976798679968006801680268036804680568066807680768086809681068116812681268136814681568168 行未改动68256826682768286829682968306831683268335 行未改动68396840684168426843684368446845684668473 行未改动685168526853685468556855685668576858685868596860686168626862686368646865686668676868686968706871687268726873687468756876687768786878687968806881688268826883688468856886688768886888688968906891689268926893689468956896689668976898689969003 行未改动690469056906690769086908690969106911691269136913691469156916691669176918691969202 行未改动6923692469256926692769276928692969306931693169326933693369346935693669376937693869396940694169426943694469456946694769476948694969506951695169526953695469553 行未改动69596960696169626963696369646965696669666967696869686969697069716971697269736974697547 行未改动7023702470257026702770277028702970307031703270317032703370347035703670377036703770387039703970407041704270436 行未改动70507051705270537054705470557056705770583 行未改动706270637064706570667066706770687069707010 行未改动708170827083708470857085708670877088708870897090709170927092709370947095709570967097709870997100710171007101710271037104710371047105710671077108710971087109711071117112711371147115711571167117711871197120712171227123712471247125712671277128712871297130713071317132713371347135713671357136713771387139713871397140714171427143714471437144714571467147714871497150715071517152715371548 行未改动71637164716571667167716771687169717071717172717171727173717471757176717771767177717871797180718171827183718471857186718771877188718971907191719271937194719471957196719771987199720072017202720172027203720472047205720672077208720972097210721172127213721472157215721672177218721972207221722272237224722472257226722672277228722972305 行未改动723672377238723972407240724172427243724472457246724672477248724972497250725172527253725472557256725772587258725972607261726272627263726472647265726672677268726972707271727272717272727372747275727672777276727772787279728072817282728372847285728572867287728872897289729072917291729272937293729472957296729772977298729972997300730173017302730373047304730573067307730873077308730973107311731173127313731473157315731673177318731973197320732173227323732373247325732673277328732873297330733073317332733273337334733473357336733773367337733873397339734073417342734373447345734673477347734873497350735173527352735373547355735673577358735873597360736173627363736373647365736673677368736973697370737173727373737473747375737673777377737873797380738173827383738473857385738673877388738873897390739173927393739373947395739673972 行未改动7400740174027403740474047405740674077408740974107410741174127412741374147415741674167417741874197420742174217422742374247425742674277428742874297430743174327433743474347435743674377438743974407441744274437443744474457445744674477448744974507451745174527453745374547455745674577457745874597459746074617462746374637464746574667467746874697469747074717472747374737474747574767477747874797479748074817482748374847484748574867487748874887489749074917492749374937494749574967497749774987499749975007501750275037504750575067507750875077508750975107511751275137513751475157516751675177518751975207520752175227522752375247525752675277528752975307531752675277528752975307531753275337533753475357536753775387538753975407541754275437542754375447545754675477548754975497550755175527553755475557556755675577558755975607560756175627563756475657565756675677568756975707571757175727573757475757576757775787579757475757576757775787579758075817582758175827583758475857586758675877588758975897590759175927593759475957596759675977598759875997600760176027603760476057605760676077607760876097610761176127613761476147615761676177618761976197620762176227623762276237624762576267627762876297630763176307631763276337634763576367637763876397638763976407641764276437644764476457646764776487649765076507651765276537654765476557656765676577658765976607661766276627663766476657666766776687669767076717672767276737674767576767675767676777678767976807680768176827683768276837684768576867686768776887689769076917691769276937694769519 行未改动771577167717771877197719772077217722772377247723772477257726772777287727772877297730773077317732773377347735773577367737773877396 行未改动7746774777487749775077507751775277537754775577567757775877597760776077617762776377637764776577667767776577667767776877697770777177717772777377747775777377747775777677777778777977797780778177817782778377847785778677867787778877887789779077917792779377937794779577957796779777987799780078017801780278037803780478057806780778077808780978107811781278127813781478157816781678177818781978207821782278227823782478247825782678277827782878297830783078317832783378347834783578367836783778387839784078417841784278437844784512 行未改动7858785978607861786278627863786478647865786678677867786878697870787178727871787278737874787578767877787878787879788078817882788278837884788578867887788878887889789078917892789278937894789578967897789878997898789979007901790279037904790579057906790779077908790979107911791179127913791479147915791679177918791979187919792079217922792379247925792679277927792879297929793079317932793379337934793579367937793879397939794079417942794379447944794579467946794779487949795079517952795279537954795579567957795779587959796079614 行未改动7966796779687969797079707971797279737974797579757976797779787979797979807981798279817982798379847985798679867987798879897990799179927993799379947995799679977998799979987999800080018002800380048005800680068007800880098010801180128012801380148015801680178018801880198020802180218022802380248025802580268027802880298030803180318032803380348035803580368037803880398040804180428042804380448045804680478048804780488049805080518052805380538054805580568057805780588059806080618062806380638064806580668067806880698069807080718072807380748075807480758076807780788079807980808081808280838084808480858086808680878088808980908090809180928092809380948095809680968097809880998100810181028102810381048105810681068107810881098110811081118112811381148114811581168117811881188119812081218122812281238124812581268127812781288129813081318132813281338134813581368137813781388139813981408141814281438144814481458146814781488149815081518152815281538154815581568157815781588159816081618162816281638164816581658166816781688169817081708171817281728173817481758176817781778178817981808180818181828183818481858185818681878188818881898190819181928193819481958196819681978198819981998200820182028202820382048205820582068207820882098210821182118212821382148215821682178217821882198219822082218222822382238224822582268226822782288229823082318230823182328233823482358236823782388238823982408241824282438244824582458246824782478248824982508250825182528253825482558255825682578258825982608261826282638264826482658266826782688269827082708271827282738273827482758276827782788279828082808281828282838283828482858286828782878288828982908291829282938294829482958296829782988299830083008301830283038304830383048305830683078308830983108310831183128312831383148315831683168317831883198320832083218322832383248325832583268327832783288329833083318332833283338334833583368337833783388339833983408341834283438343834483458345834683478348834983508351835283538354835483558356835783588359836083608361836283638363836483658366836783688368836983708371837183728373837483758376837783768377837883798380838183828382838383848384838583868387838883898388838983908391839183928393839483958396839783978398839983998400840184018402840384048405840684068407840884098410841084118412841384138414841584168416841784188419842084208421842284238424842584258426842784288428842984308431843184328433843484358435843684378438843984398440844184428443844384448445844684478448844984508450845184528453845484548455845684578457845884598460846184618462846384648465846684678468846984698470847184728473847484758475847684778478847884798480848184818482848384838484848584868486848784888489849084918492849384948495849584968497849884998500850185018502850385048505850685078507850885098510851185128512851385148515851685178517851885198520852085218522852385248525852685268527852885288529853085318532853285338534853585368537853885398540854085418542854385448545854685478548854885498550855185528553855485548555855685578558855885598560856185628562856385648565856685668567856885698570857185718572857385748575857585768577857885798579858085818582858385848584858585868587858885888589859085918592729 行未改动全部展开89 行未改动```cppstruct Save { string path; // 文件路径 int errorlevel; // 错误代码
// 方法 void setpt(string s); // 设置路径 void read_nol(); // 以文本模式打开读取 void read_bin(); // 以二进制模式打开读取406 行未改动全部展开#### 文件日志```cppstruct logger { enum error_type { error=0, info=1, warn=2, debug=3 };
void reset_logger(string path); // 初始化日志文件 void report(string s, error_type tp); // 记录日志 void stop(); // 停止日志};167 行未改动全部展开
int main() { scg(RED, BLACK); say("Hello, World!", 50);
scg(GREEN, BLACK); cout << "2 + 2 = " << PLS(2, 2) << endl;
return 0;}```
7 行未改动 file.setpt("test.txt"); file.save_nol(); file.save_o << "Hello, File!" << endl; file.save_stop();
if (fileok("test.txt")) { cout << "File created successfully!" << endl; }
return 0;}```
6 行未改动 cout << "PI = " << PI << endl; cout << "sqrt(2) = " << getSqrtNt(2, 0.0001) << endl; cout << "5! = " << fac(5) << endl; cout << "Is 17 prime? " << isPrime(17) << endl;
return 0;}```
14 行未改动
此指南涵盖了jtbg.h库的主要功能,具体使用时请参考源代码中的详细实现和注释。
## 七、下载[ilanzou(持续更新)](https://www.ilanzou.com/s/83wNo2Vk) [ilanzou(2.9)](https://www.ilanzou.com/s/gE2nYqIi) [ilanzou(持续更新)](https://www.ilanzou.com/s/83wNo2Vk)[ilanzou(2.9)](https://www.ilanzou.com/s/gE2nYqIi)## 八、源码
```cpp#undef _WIN32_WINNT53 行未改动#pragma GCC optimize("O0")//你可以换成指令: -O0#endif
#pragma cpp_std c++11 #pragma cpp_std c++11//你可以换成指令: -std=gnu++11#pragma comment(lib, "winmm.lib")//你可以换成 -lwinmm#pragma comment(lib, "wininet.lib")359 行未改动全部展开}#endif
#ifdef JTBG_HASHclass MD5 class MD5{private: typedef unsigned int uint32; typedef unsigned long long uint64; struct Context
struct Context { uint32 state[4]; uint32 count[2]; unsigned char buffer[64]; }; static void init(Context &ctx)
static void init(Context &ctx) { ctx.count[0] = ctx.count[1] = 0; ctx.state[0] = 0x67452301; ctx.state[1] = 0xefcdab89; ctx.state[2] = 0x98badcfe; ctx.state[3] = 0x10325476; } static void update(Context &ctx, const unsigned char *input, size_t length)
static void update(Context &ctx, const unsigned char *input, size_t length) { uint32 i, index, partLen;
index = (uint32)((ctx.count[0] >> 3) & 0x3F); if ((ctx.count[0] += ((uint32)length << 3)) < ((uint32)length << 3)) ctx.count[1]++; ctx.count[1] += (uint32)(length >> 29);
partLen = 64 - index; if (length >= partLen) if (length >= partLen) { memcpy(&ctx.buffer[index], input, partLen); transform(ctx.state, ctx.buffer); for (i = partLen; i + 63 < length; i += 64) transform(ctx.state, &input[i]); index = 0; } } else { i = 0; } memcpy(&ctx.buffer[index], &input[i], length - i); } static void final(unsigned char digest[16], Context &ctx)
static void final(unsigned char digest[16], Context &ctx) { unsigned char padding[64] = {0x80}; unsigned char bits[8]; size_t index, padLen;
encode(bits, ctx.count, 8); index = (uint32)((ctx.count[0] >> 3) & 0x3f); padLen = (index < 56) ? (56 - index) : (120 - index); update(ctx, padding, padLen); update(ctx, bits, 8); encode(digest, ctx.state, 16); } static void transform(uint32 state[4], const unsigned char block[64])
static void transform(uint32 state[4], const unsigned char block[64]) { uint32 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; decode(x, block, 64);
FF(a, b, c, d, x[0], 7, 0xd76aa478); FF(d, a, b, c, x[1], 12, 0xe8c7b756); FF(c, d, a, b, x[2], 17, 0x242070db); FF(b, c, d, a, x[3], 22, 0xc1bdceee);8 行未改动 FF(a, b, c, d, x[12], 7, 0x6b901122); FF(d, a, b, c, x[13], 12, 0xfd987193); FF(c, d, a, b, x[14], 17, 0xa679438e); FF(b, c, d, a, x[15], 22, 0x49b40821);
GG(a, b, c, d, x[1], 5, 0xf61e2562); GG(d, a, b, c, x[6], 9, 0xc040b340); GG(c, d, a, b, x[11], 14, 0x265e5a51); GG(b, c, d, a, x[0], 20, 0xe9b6c7aa);8 行未改动 GG(a, b, c, d, x[13], 5, 0xa9e3e905); GG(d, a, b, c, x[2], 9, 0xfcefa3f8); GG(c, d, a, b, x[7], 14, 0x676f02d9); GG(b, c, d, a, x[12], 20, 0x8d2a4c8a);
HH(a, b, c, d, x[5], 4, 0xfffa3942); HH(d, a, b, c, x[8], 11, 0x8771f681); HH(c, d, a, b, x[11], 16, 0x6d9d6122); HH(b, c, d, a, x[14], 23, 0xfde5380c);8 行未改动 HH(a, b, c, d, x[9], 4, 0xd9d4d039); HH(d, a, b, c, x[12], 11, 0xe6db99e5); HH(c, d, a, b, x[15], 16, 0x1fa27cf8); HH(b, c, d, a, x[2], 23, 0xc4ac5665);
II(a, b, c, d, x[0], 6, 0xf4292244); II(d, a, b, c, x[7], 10, 0x432aff97); II(c, d, a, b, x[14], 15, 0xab9423a7); II(b, c, d, a, x[5], 21, 0xfc93a039);8 行未改动 II(a, b, c, d, x[4], 6, 0xf7537e82); II(d, a, b, c, x[11], 10, 0xbd3af235); II(c, d, a, b, x[2], 15, 0x2ad7d2bb); II(b, c, d, a, x[9], 21, 0xeb86d391);
state[0] += a; state[1] += b; state[2] += c; state[3] += d; }
static inline uint32 F(uint32 x, uint32 y, uint32 z) { return (x & y) | (~x & z); } static inline uint32 G(uint32 x, uint32 y, uint32 z) { return (x & z) | (y & ~z); } static inline uint32 H(uint32 x, uint32 y, uint32 z) { return x ^ y ^ z; } static inline uint32 I(uint32 x, uint32 y, uint32 z) { return y ^ (x | ~z); } static inline void FF(uint32 &a, uint32 b, uint32 c, uint32 d, uint32 x, uint32 s, uint32 t)
static inline void FF(uint32 &a, uint32 b, uint32 c, uint32 d, uint32 x, uint32 s, uint32 t) { a += F(b, c, d) + x + t; a = (a << s) | (a >> (32 - s)); a += b; } static inline void GG(uint32 &a, uint32 b, uint32 c, uint32 d, uint32 x, uint32 s, uint32 t)
static inline void GG(uint32 &a, uint32 b, uint32 c, uint32 d, uint32 x, uint32 s, uint32 t) { a += G(b, c, d) + x + t; a = (a << s) | (a >> (32 - s)); a += b; } static inline void HH(uint32 &a, uint32 b, uint32 c, uint32 d, uint32 x, uint32 s, uint32 t)
static inline void HH(uint32 &a, uint32 b, uint32 c, uint32 d, uint32 x, uint32 s, uint32 t) { a += H(b, c, d) + x + t; a = (a << s) | (a >> (32 - s)); a += b; } static inline void II(uint32 &a, uint32 b, uint32 c, uint32 d, uint32 x, uint32 s, uint32 t)
static inline void II(uint32 &a, uint32 b, uint32 c, uint32 d, uint32 x, uint32 s, uint32 t) { a += I(b, c, d) + x + t; a = (a << s) | (a >> (32 - s)); a += b; } static void encode(unsigned char *output, const uint32 *input, size_t length)
static void encode(unsigned char *output, const uint32 *input, size_t length) { for (size_t i = 0, j = 0; j < length; i++, j += 4) for (size_t i = 0, j = 0; j < length; i++, j += 4) { output[j] = (unsigned char)(input[i] & 0xFF); output[j + 1] = (unsigned char)((input[i] >> 8) & 0xFF); output[j + 2] = (unsigned char)((input[i] >> 16) & 0xFF); output[j + 3] = (unsigned char)((input[i] >> 24) & 0xFF); } } static void decode(uint32 *output, const unsigned char *input, size_t length)
static void decode(uint32 *output, const unsigned char *input, size_t length) { for (size_t i = 0, j = 0; j < length; i++, j += 4) output[i] = ((uint32)input[j]) | (((uint32)input[j + 1]) << 8) | (((uint32)input[j + 2]) << 16) | (((uint32)input[j + 3]) << 24); }
public: static string hash(const string &input) static string hash(const string &input) { Context ctx; init(ctx); update(ctx, (const unsigned char*)input.c_str(), input.length());7 行未改动 }};//MD5::hash(str)
unsigned long long pHash(const string& s) unsigned long long pHash(const string& s){ const unsigned long long base = 911382629ULL; const unsigned long long mod = 1000000000000000003ULL; unsigned long long hashValue = 0;
// 使用传统for循环兼容C++98 for (size_t i = 0; i < s.size(); ++i) for (size_t i = 0; i < s.size(); ++i) { char c = s[i]; hashValue = (hashValue * base + static_cast<unsigned long long>(c)) % mod; }
return hashValue;}
struct StringHash struct StringHash{ static const unsigned long long base = 911382629ULL; static const unsigned long long mod = 1000000000000000003ULL; vector<unsigned long long> hash; vector<unsigned long long> power; StringHash(const string& s) StringHash(const string& s) { int n = s.size(); hash.resize(n + 1); power.resize(n + 1); power[0] = 1;
for (int i = 0; i < n; ++i) { hash[i+1] = (hash[i] * base + static_cast<unsigned long long>(s[i])) % mod; power[i+1] = (power[i] * base) % mod; } } // 获取子串s[l..r]的哈希值(0-based,包含l和r) unsigned long long getHash(int l, int r) unsigned long long getHash(int l, int r) { int len = r - l + 1; unsigned long long res = (hash[r+1] - hash[l] * power[len]) % mod; if(false) return res+mod;4 行未改动//StringHash strHash(str);//cout << "前缀哈希完整字符串: " << strHash.getHash(0, str.size()-1) << endl;//cout << "子串哈希(0-4): " << strHash.getHash(0, 4) << " (对应\"Hello\")" << endl;
size_t Hash(const string& s) size_t Hash(const string& s){ size_t hashVal = 0; for (size_t i = 0; i < s.size(); ++i) for (size_t i = 0; i < s.size(); ++i) { // 简单的哈希组合算法 hashVal = hashVal * 31 + static_cast<size_t>(s[i]); } return hashVal;} }
string FileMD5(string path){ ifstream file(path,ios::in|ios::binary); if (!file.is_open()) if (!file.is_open()) { return ""; } string fileContent; file.seekg(0,ios::end); size_t fileSize = static_cast<size_t>(file.tellg()); file.seekg(0,ios::beg); fileContent.reserve(fileSize); fileContent.assign(istreambuf_iterator<char>(file),istreambuf_iterator<char>()); if (!file && !file.eof()) if (!file && !file.eof()) { return ""; } return MD5::hash(fileContent);}#endif
#ifdef JTBG_FILEbool Isfileext(const string& filePath) bool Isfileext(const string& filePath){ ifstream file(filePath, ios::in | ios::binary); bool exists = file.good(); file.close();58 行未改动
inline void read((bool)*f{bool})
//检测文件读写是否bool fileok(const string &filename) bool fileok(const string &filename){ ifstream file(filename); return file.good();}12 行未改动 } return ;}
void paused(string s) void paused(string s){ cout<<s<<endl; system("pause > nul"); return ;5 行未改动 exit(num); return num;}
enum Color enum Color{ BLACK = 0, BLUE = 1, GREEN = 2,34 行未改动 return ;}
//控制台光标位置控制void setcursor(int x,int y) void setcursor(int x,int y){ COORD coord; coord.X = x; coord.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);}
//清除控制台指定区域内容void clearCA(int x, int y, int width, int height) void clearCA(int x, int y, int width, int height){ for(int i=0;i<height;i++) { setcursor(x, y + i); cout << string(width, ' '); }}
//隐藏/显示控制台光标void setCVis(bool visible) void setCVis(bool visible){ CONSOLE_CURSOR_INFO cursorInfo = {1, visible}; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursorInfo);}
//获取控制台尺寸void getCSize(int &width,int &height) void getCSize(int &width,int &height){ CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); width = csbi.srWindow.Right - csbi.srWindow.Left + 1; height = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;}
void flushed() void flushed(){ cin.ignore(numeric_limits<streamsize>::max(), '\n'); cin.clear(); return ;7 行未改动 return a+rand()%(b+1);}
//生成指定长度的随机字符串string randS(int length) string randS(int length){ const string chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; string result; for (int i = 0; i < length; ++i) { result += chars[rand() % chars.size()]; } return result;}
double random(double min, double max) double random(double min, double max){ return min + (max - min) * (rand() / (double)RAND_MAX);}#endif
#ifdef JTBG_STRING/** @brief 在字符串中查找匹配指定模式的位置* ** @param s 要搜索的目标字符串* @param pattern 匹配模式,支持通配符:* %d - 匹配整数* %Nd - 匹配宽度为N的整数(必须正好N位数字)4 行未改动* %c - 匹配单个字符* %Nc - 匹配N个字符* %% - 匹配百分号字符* 普通字符 - 直接匹配对应字符* ** @return int 返回匹配开始的索引位置,如果未找到匹配则返回-1* ** @example* find_in_string("123abc", "%d%s") // 返回0,匹配"123abc"* find_in_string("hello 123", "%s %d") // 返回0,匹配"hello 123"* find_in_string("abc123", "%3s%d") // 返回0,匹配"abc123"* find_in_string("hello world", "%k") // 返回0,匹配整个字符串* find_in_string("5[hi]", "%d[%2s]") // 返回0,匹配"5[hi]"* ** @note 模式匹配是贪婪的,会尝试从每个位置开始匹配*/int find_in_string(const string& s, const string& pattern){ int s_len = s.length(); int p_len = pattern.length();
// 尝试从每个位置开始匹配 for (int start = 0; start <= s_len; ++start) { int i = start; // 目标字符串的当前位置 int j = 0; // 模式的当前位置 bool matched = true;
// 遍历模式字符串 while (j < p_len && i <= s_len) { // 检查是否是通配符4 行未改动 { matched = false; break; }
j++; // 跳过%
// 解析宽度限定符(如果有) int width = 0; bool has_width = false;
while (j < p_len && isdigit(pattern[j])) { width = width * 10 + (pattern[j] - '0'); j++; has_width = true; }
// 确保有说明符 if (j >= p_len) { matched = false; break; }
char specifier = pattern[j]; j++; // 跳过说明符
// 根据说明符处理不同类型的匹配 switch (specifier) { case 'd': // 匹配整数 if (i >= s_len) { matched = false; break; }
if (has_width) { // 固定宽度整数:必须正好匹配width位数字 for (int k = 0; k < width; k++)13 行未改动 { matched = false; break; }
// 可选符号 if (s[i] == '-' || s[i] == '+') { i++; }
// 匹配一个或多个数字 if (i >= s_len || !isdigit(s[i])) { matched = false; break; }
while (i < s_len && isdigit(s[i])) { i++; } } break;
case 's': // 匹配非空白字符串 if (i >= s_len) { matched = false; break; }
if (has_width) { // 固定宽度字符串:匹配width个任意字符(包括空白符) for (int k = 0; k < width; k++)13 行未改动 { matched = false; break; }
while (i < s_len && !isspace(s[i])) { i++; } } break;
case 'k': // 匹配任意字符串(可包含空白符) if (i >= s_len) { matched = false; break; }
if (has_width) { // 固定宽度:匹配width个任意字符 for (int k = 0; k < width; k++)11 行未改动 // 变长:匹配到字符串结束或遇到模式中的下一个字符 // 这里我们采用贪婪匹配,直到字符串结束 // 实际的停止条件会在外层循环中处理 int next_char = (j < p_len) ? pattern[j] : -1;
// 如果没有下一个字符,匹配到字符串结束 if (next_char == -1) { i = s_len;7 行未改动 } } } break;
case 'c': // 匹配字符 if (i >= s_len) { matched = false; break; }
if (has_width) { // 固定宽度:匹配width个字符 for (int k = 0; k < width; k++)11 行未改动 // 单个字符 i++; } break;
case '%': // 匹配百分号 if (i >= s_len || s[i] != '%') { matched = false;2 行未改动 { i++; } break;
default: matched = false; } }7 行未改动 } i++; j++; }
if (!matched) { break; } }
// 如果模式完全匹配且目标字符串也匹配完毕 if (matched && j == p_len) { return start; } }
return -1; // 未找到匹配}
template<typename T>22 行未改动{ int m = s1.length(); int n = s2.length(); vector<vector<int>> dp(m + 1, vector<int>(n + 1));
for (int i = 0; i <= m; i++) { dp[i][0] = i; }
for (int j = 0; j <= n; j++) { dp[0][j] = j; }
for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) {8 行未改动 dp[i - 1][j - 1] + 1}); } } }
return dp[m][n];}
template<typename T>10 行未改动 if (s1.empty() && s2.empty()) { return 100; }
int maxLen = max(s1.length(), s2.length()); if (maxLen == 0) { return 0; }
int distance = editDistance(s1, s2); return (int)((1.0 - (double)distance / maxLen) * 100.0);}
//检查字符串是否为数字(整数或小数)bool isNumber(const string& str) bool isNumber(const string& str){ if (str.empty()) return false; size_t start = 0; if (str[0] == '+' || str[0] == '-') start = 1; bool hasDot = false; for (size_t i = start; i < str.size(); ++i) for (size_t i = start; i < str.size(); ++i) { if (str[i] == '.') if (str[i] == '.') { if (hasDot) return false; hasDot = true; } else if (!isdigit(str[i])) else if (!isdigit(str[i])) { return false; } }23 行未改动 } return ;}
void Testsuper(string &s) void Testsuper(string &s){ if (s.empty()) return; s[0] = toupper(s[0]); for (size_t i = 1; i < s.size();i++) for (size_t i = 1; i < s.size();i++) { s[i]=tolower(s[i]); }}7 行未改动{ if(t!=-1) { t*=100; while(t--) while(t--) { if (_kbhit()) if (_kbhit()) { int key = _getch(); return key; } } return -1; } else { while(1) while(1) { if (_kbhit()) if (_kbhit()) { int key = _getch(); return key; }45 行未改动{private: using Clock = chrono::high_resolution_clock; using TimePoint = chrono::time_point<Clock>;
TimePoint start_; TimePoint pause_; bool isRunning_; chrono::duration<double> elapsed_;
public: Timer() : isRunning_(false), elapsed_(0) {} void starttick() void starttick() { if (!isRunning_) if (!isRunning_) { start_ = Clock::now(); isRunning_ = true; } } void pausetick() void pausetick() { if (isRunning_) if (isRunning_) { pause_ = Clock::now(); elapsed_ += pause_ - start_; isRunning_ = false; } } void resettick() void resettick() { isRunning_ = false; elapsed_ = chrono::duration<double>(0); }2 行未改动 isRunning_ = false; elapsed_ = chrono::duration<double>(t); return ; } double timesec() const double timesec() const { if (isRunning_) if (isRunning_) { auto now = Clock::now(); return (elapsed_ + (now - start_)).count(); } return elapsed_.count(); } double timemst() const double timemst() const { return timesec() * 1000.0; }};46 行未改动 }}string getArchName(int archCode){ switch (archCode) switch (archCode) { case SX64: return "x64 (AMD64)"; case SX86: return "x86 (Intel)"; case SARM32: return "ARM (32-bit)";29 行未改动{ char szPath[MAX_PATH]; GetModuleFileName(NULL, szPath, MAX_PATH); SHELLEXECUTEINFO sei; ZeroMemory(&sei,sizeof(sei)); ZeroMemory(&sei,sizeof(sei)); sei.cbSize = sizeof(sei); sei.lpVerb = "runas"; sei.lpFile = szPath; sei.hwnd = NULL;4 行未改动bool AddToCurrentUserStartup(const string& appName, const string& appPath){ HKEY hKey; LONG result;
// 使用 RegOpenKeyExA 和 RegSetValueExA (ANSI 版本) result = RegOpenKeyExA( HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_WRITE, &hKey ); if (result != ERROR_SUCCESS)
if (result != ERROR_SUCCESS) { return false; }
// 如果路径包含空格,用引号包围 string finalPath = appPath; if (appPath.find(' ') != string::npos && appPath[0] != '\"') if (appPath.find(' ') != string::npos && appPath[0] != '\"') { finalPath = "\"" + appPath + "\""; }
result = RegSetValueExA( hKey, appName.c_str(), 0, REG_SZ, (const BYTE*)finalPath.c_str(), finalPath.size() + 1 );
RegCloseKey(hKey); return (result == ERROR_SUCCESS);}bool isRun(const char* processName) bool isRun(const char* processName){
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnapshot == INVALID_HANDLE_VALUE) return true; PROCESSENTRY32 pe32; pe32.dwSize = sizeof(PROCESSENTRY32); if (Process32First(hSnapshot, &pe32)) if (Process32First(hSnapshot, &pe32)) { do { if (strcmp(pe32.szExeFile, processName) == 0) { if (strcmp(pe32.szExeFile, processName) == 0) {
CloseHandle(hSnapshot); return true; }
}while (Process32Next(hSnapshot, &pe32)); } CloseHandle(hSnapshot); return false; return false;}
void Hide() void Hide(){ HWND hwnd = GetForegroundWindow(); // 获取当前窗口句柄 if (hwnd) ShowWindow(hwnd, SW_HIDE); // 隐藏窗口}
void Show() void Show(){ HWND hwnd = GetForegroundWindow(); // 获取当前窗口句柄 if (hwnd) ShowWindow(hwnd, SW_SHOW); // 隐藏窗口}12 行未改动 return static_cast<long long>(file.tellg());}
//延迟函数(高精度ms)void msSleep(int milliseconds) void msSleep(int milliseconds){ auto start = chrono::high_resolution_clock::now(); while (chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() < milliseconds);}
//计算文件夹内文件数量(仅统计一级目录)int getFileCountInDir(const string& dirPath) int getFileCountInDir(const string& dirPath){ int count = 0; WIN32_FIND_DATA findData; HANDLE hFind = FindFirstFile((dirPath + "\\*").c_str(), &findData); if (hFind == INVALID_HANDLE_VALUE) return -1; do do { if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { count++; // 只统计文件,不统计文件夹 } } while (FindNextFile(hFind, &findData) != 0);73 行未改动}#endif
#ifdef JTBG_DECANDENCstring xorFile(const string& filePath,const string& key) string xorFile(const string& filePath,const string& key){ if (key.empty()) if (key.empty()) { return ""; } ifstream file(filePath.c_str(), ios::in | ios::binary); if (!file.is_open()) if (!file.is_open()) { return ""; } string fileContent; char buffer[4096]; while (file.read(buffer, sizeof(buffer))) while (file.read(buffer, sizeof(buffer))) { fileContent.append(buffer, sizeof(buffer)); } fileContent.append(buffer, file.gcount()); const size_t keyLen = key.size(); size_t keyIndex = 0; for (string::iterator it = fileContent.begin(); it != fileContent.end(); ++it) for (string::iterator it = fileContent.begin(); it != fileContent.end(); ++it) { *it = static_cast<char>(static_cast<uint8_t>(*it) ^ static_cast<uint8_t>(key[keyIndex])); keyIndex = (keyIndex + 1) % keyLen; } return fileContent;}
void xortoFile(const string& filePath,const string& key) void xortoFile(const string& filePath,const string& key){ if (key.empty()) if (key.empty()) { return ; } ifstream file(filePath.c_str(),ios::in | ios::binary); if (!file.is_open()) if (!file.is_open()) { return ; return ; } string fileContent; char buffer[4096]; while (file.read(buffer, sizeof(buffer))) while (file.read(buffer, sizeof(buffer))) { fileContent.append(buffer, sizeof(buffer)); } fileContent.append(buffer, file.gcount()); file.close(); const size_t keyLen = key.size(); size_t keyIndex = 0; for (string::iterator it = fileContent.begin(); it != fileContent.end(); ++it) for (string::iterator it = fileContent.begin(); it != fileContent.end(); ++it) { *it = static_cast<char>(static_cast<uint8_t>(*it) ^ static_cast<uint8_t>(key[keyIndex])); keyIndex = (keyIndex + 1) % keyLen; } ofstream outFile(filePath.c_str(), ios::out | ios::binary | ios::trunc); if (outFile.is_open()) if (outFile.is_open()) { outFile.write(fileContent.data(), fileContent.size()); outFile.close(); }}
void caesarFile(const string& filePath,int shift) void caesarFile(const string& filePath,int shift){ shift %= 256; if (shift < 0) if (shift < 0) { shift += 256; } ifstream file(filePath.c_str(), ios::in | ios::binary); if (!file.is_open()) if (!file.is_open()) { return ; } string fileContent; char buffer[4096]; while (file.read(buffer, sizeof(buffer))) while (file.read(buffer, sizeof(buffer))) { fileContent.append(buffer, sizeof(buffer)); } fileContent.append(buffer, file.gcount()); file.close(); for(string::iterator it = fileContent.begin(); it != fileContent.end();it++) file.close(); for(string::iterator it = fileContent.begin(); it != fileContent.end();it++) { *it = static_cast<char>((static_cast<uint8_t>(*it) + shift) % 256); } ofstream outFile(filePath.c_str(), ios::out | ios::binary | ios::trunc); if (outFile.is_open()) if (outFile.is_open()) { outFile.write(fileContent.data(), fileContent.size()); outFile.close(); }}//加void FileCEnc(const string& filePath, int shift) void FileCEnc(const string& filePath, int shift){ caesarFile(filePath, shift);}//解void FileCDec(const string& filePath, int shift) void FileCDec(const string& filePath, int shift){ caesarFile(filePath, 256 - (shift % 256)); caesarFile(filePath, 256 - (shift % 256));}
//加密string CEnc(const string& input, int shift) string CEnc(const string& input, int shift){ shift %= 256; if (shift < 0) if (shift < 0) { shift += 256; } string result = input; const size_t len = result.size(); for (size_t i = 0; i < len; ++i) for (size_t i = 0; i < len; ++i) { result[i] = static_cast<char>((static_cast<uint8_t>(result[i]) + shift) % 256); } return result;}
//解密string CDec(const string& input, int shift) string CDec(const string& input, int shift){ shift %= 256; if (shift < 0) if (shift < 0) { shift += 256; } return CEnc(input, 256 - shift);}
//xor加/解密string xorpass(const string &str, const string &key) string xorpass(const string &str, const string &key){ string result = str; size_t keyLen = key.size(); if (keyLen == 0) return result;3 行未改动 } return result;}
string base64up(const string &str,const string &base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/") string base64up(const string &str,const string &base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"){
string result; int val = 0, valBits = 0; for (unsigned char c : str) for (unsigned char c : str) { val = (val << 8) + c; valBits += 8; while (valBits >= 6) { result += base64Chars[(val >> (valBits - 6)) & 0x3F]; valBits -= 6; } } if (valBits > 0) if (valBits > 0) { val <<= (6 - valBits); result += base64Chars[val & 0x3F]; } while (result.size() % 4 != 0) while (result.size() % 4 != 0) { result += '='; } return result;}string base64dec(const string &str,const string base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/") string base64dec(const string &str,const string base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"){ string result; vector<int> val(4, -1); for (size_t i = 0; i < str.size(); ++i) vector<int> val(4, -1); for (size_t i = 0; i < str.size(); ++i) { char c = str[i]; if (c == '=') break; size_t pos = base64Chars.find(c); if (pos == string::npos) continue; val[i % 4] = pos; if (i % 4 == 3) if (i % 4 == 3) { result += (val[0] << 2) + ((val[1] >> 4) & 0x3); if (val[2] != -1) if (val[2] != -1) { result += ((val[1] << 4) & 0xF0) + ((val[2] >> 2) & 0xF); } if (val[3] != -1) if (val[3] != -1) { result += ((val[2] << 6) & 0xC0) + val[3]; } val.assign(4, -1);47 行未改动#define ftop(a,b) NumbertoPercent((a),(b))
inline double getSqrtNt(double n,double t){ if (n < 0) if (n < 0) { return NAN; } if (t <= 0) if (t <= 0) { return NAN; } if (n == 0) return 0; double xn = n / 2.0; double xn1 = 0.0; const int MAX_ITER = 1000; int iterCount = 0; do do { xn1 = xn - (xn * xn - n) / (2 * xn); if (fabs(xn1 - xn) < t) if (fabs(xn1 - xn) < t) { break; } xn = xn1; iterCount++; } while (iterCount < MAX_ITER); if (iterCount >= MAX_ITER) if (iterCount >= MAX_ITER) { return NAN; } return xn1;}
//角度转弧度inline double toRadians(double degrees) inline double toRadians(double degrees){ return degrees * DEG_TO_RAD;}
// 弧度转角度inline double toDegrees(double radians) inline double toDegrees(double radians){ return radians * RAD_TO_DEG;}
// 计算阶乘inline long long fac(int n) inline long long fac(int n){ if(n<0) return -1; long long result = 1; for (int i = 2; i <= n; ++i) for (int i = 2; i <= n; ++i) { result *= i; } return result;}
inline double qpow(double base, int exponent) inline double qpow(double base, int exponent){ if (exponent==0) return 1.0; if (base==0) return 0.0; bool isNegative = exponent < 0; unsigned int absExponent = static_cast<unsigned int>(isNegative ? -exponent : exponent); double result = 1.0; double current = base; while (absExponent > 0) while (absExponent > 0) { if (absExponent % 2 == 1) if (absExponent % 2 == 1) { result *= current; } current *= current; absExponent /= 2; current *= current; absExponent /= 2; } return isNegative ? 1.0 / result : result;}
inline long long ipow(long long base, int exponent){ if (exponent == 0) return 1; if (base == 0) return 0;
bool isNegative = false; unsigned int absExp; if (exponent < 0) if (exponent < 0) { isNegative = true; absExp = static_cast<unsigned int>(-exponent); } else } else { absExp = static_cast<unsigned int>(exponent); }
long long result = 1; long long current = base; while (absExp > 0)
while (absExp > 0) { if (absExp & 1) if (absExp & 1) { result *= current; } current *= current; absExp >>= 1; }
return isNegative ? (result == 0 ? 0 : 1) : result;}
inline long long GetA(int a, int b) inline long long GetA(int a, int b){ if(a < 0 || b < 0 || a < b) if(a < 0 || b < 0 || a < b) { return -1; } if (b == 0) { if (b == 0) { return 1; } long long result = 1; for (int i = 0; i < b; ++i) for (int i = 0; i < b; ++i) { result *= (a - i); if (result < 0) if (result < 0) { return -1; } } return result;}
inline long long GetC(int a, int b){ if (a < 0 || b < 0 || a < b) if (a < 0 || b < 0 || a < b) { return -1; } if (b == 0 || a == b) { if (b == 0 || a == b) { return 1; } b = min(b, a - b); long long result = 1; for (int i = 1; i <= b; ++i) for (int i = 1; i <= b; ++i) { result = result * (a - b + i) / i; if (result < 0) if (result < 0) { return -1; } }34 行未改动 int sqrt_to = static_cast<int>(sqrt(to)); for (int i = 2; i <= sqrt_to; ++i) { if (is_prime[i]) { { for (int j = i * i; j <= to; j += i) { is_prime[j] = false; } } } for (int num = from; num <= to; ++num) for (int num = from; num <= to; ++num) { if (is_prime[num]) if (is_prime[num]) { primes.push_back(num); } }2 行未改动
inline vector<int> MakePrimelist_OLaShai(int from, int to){ vector<int> primes; if (from > to || to < 2) { if (from > to || to < 2) { return primes; } from=max(from, 2); vector<bool> is_prime(to + 1, true); is_prime[0] = is_prime[1] = false; vector<int> all_primes; for(int i = 2; i <= to; ++i) for(int i = 2; i <= to; ++i) { if (is_prime[i]) { all_primes.push_back(i);4 行未改动 { break; } is_prime[i * p] = false; if (i % p == 0) if (i % p == 0) { break; } } } for(int j=0;j<int(all_primes.size());++j) { int p = all_primes[j]; if (p >= from && p <= to) if (p >= from && p <= to) { primes.push_back(p); } }23 行未改动 } } vector<int> primes; from = max(from, 2); for (int p : cache_all_primes) for (int p : cache_all_primes) { if (p >= from && p <= to) primes.push_back(p); } return primes;17 行未改动 shift++; } while ((a & 1) == 0) a >>= 1; do do { while ((b & 1) == 0) b >>= 1; if (a < b)21 行未改动 shift++; } while ((a & 1) == 0) a >>= 1; do do { while ((b & 1) == 0) b >>= 1; if (a < b)6 行未改动inline long long jtbg_lcm(long long a, long long b, bool usesystem = 0){ if (a == 0 || b == 0) return 0; long long gcd_val = jtbg_gcd(a, b, usesystem); if (gcd_val == 0) return 0; if (gcd_val == 0) return 0; // lcm(a, b) = |a * b| / gcd(a, b) return llabs(a / gcd_val * b);}
inline int jtbg_lcm(int a, int b, bool usesystem = 0){ if (a == 0 || b == 0) return 0; int gcd_val = jtbg_gcd(a, b, usesystem); if (gcd_val == 0) return 0;
// lcm(a, b) = |a * b| / gcd(a, b) return abs(a / gcd_val * b);}
inline long long jtbg_lcm_multi(const vector<long long>& numbers, bool usesystem = 0){ if (numbers.empty()) return 0;
long long result = numbers[0]; for (size_t i = 1; i < numbers.size(); ++i) { result = jtbg_lcm(result, numbers[i], usesystem); if (result == 0) break;103 行未改动全部展开{ if (n < 0) return -1; if (n == 0) return 0; if (n == 1) return 1;
long long a = 0, b = 1; for (int i = 2; i <= n; ++i) for (int i = 2; i <= n; ++i) { long long temp = a + b; a = b; b = temp;4 行未改动// 判断是否为斐波那契数inline bool jtbg_isFibonacci(int n){ if (n < 0) return false;
// 一个数是斐波那契数当且仅当 5*n^2+4 或 5*n^2-4 是完全平方数 int check1 = 5 * n * n + 4; int check2 = 5 * n * n - 4;
return jtbg_isPerfectSquare(check1) || jtbg_isPerfectSquare(check2);}
// 计算数字的位数inline int jtbg_countDigits(long long n){ if (n == 0) return 1; int count = 0; n = llabs(n); while (n > 0) while (n > 0) { n /= 10; count++; }4 行未改动inline int jtbg_digitSum(long long n){ int sum = 0; n = llabs(n); while (n > 0) while (n > 0) { sum += n % 10; n /= 10; }5 行未改动{ long long reversed = 0; bool negative = n < 0; n = llabs(n); while (n > 0)
while (n > 0) { reversed = reversed * 10 + n % 10; n /= 10; }
return negative ? -reversed : reversed;}
// 判断回文数266 行未改动全部展开 }; long long gcd_val = gcd(a, b); a /= gcd_val; b /= gcd_val;
while (b % 2 == 0) { b /= 2; } while (b % 5 == 0) { b /= 5; }
if (b == 1) { return 0; }
long long phi_b = euler_phi(b); vector<long long> divisors = get_divisors(phi_b); for (long long k : divisors) { if (quick_pow(10, k, b) == 1) { return k; } }
return -1;}
inline long long int_to_long_long(int i)31 行未改动inline int jtbg_divcnt(int n){ if (n <= 0) return 0; if (n == 1) return 1;
int cnt = 1; int tmp = n; for (int i = 2; i * i <= tmp; i++) {13 行未改动inline int jtbg_divsum(int n){ if (n <= 0) return 0; if (n == 1) return 1;
int sum = 1; int tmp = n; for (int i = 2; i * i <= tmp; i++) {18 行未改动inline long long jtbg_crt(vector<long long> rem, vector<long long> mod){ if (rem.size() != mod.size()) return -1; int k = rem.size();
long long x = 0; long long M = 1; for (int i = 0; i < k; i++) M *= mod[i];
for (int i = 0; i < k; i++) { long long Mi = M / mod[i]; long long inv = jtbg_modinv(Mi, mod[i]);9 行未改动inline long long jtbg_perm(long long n, long long k){ if (n < 0 || k < 0 || k > n) return 0; if (k == 0) return 1;
long long res = 1; for (long long i = 0; i < k; i++) { if (res > LLONG_MAX / (n - i)) return -1;6 行未改动inline long long jtbg_comb(long long n, long long k){ if (n < 0 || k < 0 || k > n) return 0; if (k == 0 || k == n) return 1;
if (k > n - k) k = n - k; long long res = 1; for (long long i = 1; i <= k; i++) {7 行未改动inline long long jtbg_catalan(int n){ if (n < 0) return 0; if (n == 0) return 1;
long long res = 1; for (int i = 1; i <= n; i++) { res = res * (4 * i - 2) / (i + 1);155 行未改动全部展开inline double jtbg_root_bisect(double (*f)(double), double a, double b, double eps = 1e-10, int maxit = 1000){ double fa = f(a); double fb = f(b);
if (fa * fb > 0) return NAN; // 同号,区间内可能无根
// 确保 fa < 0 < fb if (fa > 0) { swap(a, b); swap(fa, fb); }
for (int i = 0; i < maxit; i++) { double mid = (a + b) / 2; double fm = f(mid);
if (fabs(fm) < eps || (b - a) < eps) return mid;
if (fm < 0) { a = mid; fa = fm;25 行未改动 double a3 = 1.421413741; double a4 = -1.453152027; double a5 = 1.061405429; double p = 0.3275911;
int sign = (x < 0) ? -1 : 1; x = fabs(x); double t = 1.0 / (1.0 + p * x); double y = 1.0 - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t * exp(-x * x);28 行未改动inline bool jtbg_mat2_inv(double m[2][2], double inv[2][2]){ double det = jtbg_mat2_det(m); if (fabs(det) < 1e-10) return false;
double inv_det = 1.0 / det; inv[0][0] = m[1][1] * inv_det; inv[0][1] = -m[0][1] * inv_det; inv[1][0] = -m[1][0] * inv_det;38 行未改动inline bool jtbg_vec_norm(double v[], int n){ double len = jtbg_vec_len(v, n); if (len < 1e-10) return false;
for (int i = 0; i < n; i++) { v[i] /= len; }30 行未改动inline Complex jtbg_cdiv(Complex a, Complex b){ double denom = b.re*b.re + b.im*b.im; if (fabs(denom) < 1e-10) return Complex(NAN, NAN); return Complex((a.re*b.re + a.im*b.im)/denom, return Complex((a.re*b.re + a.im*b.im)/denom, (a.im*b.re - a.re*b.im)/denom);}
// 复数模长26 行未改动// 复数幂 (a+bi)^ninline Complex jtbg_cpow(Complex c, int n){ if (n == 0) return Complex(1, 0);
Complex result(1, 0); Complex base = c; bool neg = false;
if (n < 0) { n = -n; neg = true; }
while (n > 0) { if (n & 1) result = jtbg_cmul(result, base); base = jtbg_cmul(base, base); n >>= 1; }
if (neg) { double denom = result.re*result.re + result.im*result.im; if (fabs(denom) < 1e-10) return Complex(NAN, NAN);58 行未改动inline double jtbg_rand_norm(double mu, double sigma){ static bool hasSpare = false; static double spare;
if (hasSpare) { hasSpare = false; return mu + sigma * spare; }
double u, v, s; do { u = (rand() / (RAND_MAX + 1.0)) * 2.0 - 1.0; v = (rand() / (RAND_MAX + 1.0)) * 2.0 - 1.0; s = u*u + v*v; } while (s >= 1.0 || s == 0.0);
s = sqrt(-2.0 * log(s) / s); spare = v * s; hasSpare = true; return mu + sigma * u * s;7 行未改动 return a + (b - a) * t;}
// 双线性插值inline double jtbg_bilerp(double q11, double q12, double q21, double q22, inline double jtbg_bilerp(double q11, double q12, double q21, double q22, double x, double y){ double r1 = jtbg_lerp(q11, q21, x); double r2 = jtbg_lerp(q12, q22, x);37 行未改动 { out[0] = in[0]; return; }
Complex* even = new Complex[n/2]; Complex* odd = new Complex[n/2]; Complex* even_fft = new Complex[n/2]; Complex* odd_fft = new Complex[n/2];
for (int i = 0; i < n/2; i++) { even[i] = in[2*i]; odd[i] = in[2*i + 1]; }
jtbg_fft(even, even_fft, n/2, inverse); jtbg_fft(odd, odd_fft, n/2, inverse);
double angle = (inverse ? 2 : -2) * PI / n; Complex w_n(cos(angle), sin(angle)); Complex w(1, 0);
for (int k = 0; k < n/2; k++) { Complex temp = jtbg_cmul(w, odd_fft[k]); out[k] = jtbg_cadd(even_fft[k], temp);6 行未改动 out[k + n/2].im /= 2; } w = jtbg_cmul(w, w_n); }
delete[] even; delete[] odd; delete[] even_fft; delete[] odd_fft;15 行未改动
//===================================== 优化算法 =====================================
// 梯度下降inline double jtbg_grad_desc(double (*f)(double), double x0, inline double jtbg_grad_desc(double (*f)(double), double x0, double lr = 0.01, int iter = 1000){ double x = x0; double h = 1e-5;
for (int i = 0; i < iter; i++) { double grad = (f(x+h) - f(x-h)) / (2*h); x = x - lr * grad; } return x;}
// 黄金分割搜索(求最小值)inline double jtbg_golden_search(double (*f)(double), double a, double b, inline double jtbg_golden_search(double (*f)(double), double a, double b, double tol = 1e-7){ const double phi = (sqrt(5) - 1) / 2; double c = b - phi * (b - a); double d = a + phi * (b - a);
while (fabs(c - d) > tol) { if (f(c) < f(d)) {16 行未改动// 十进制转二进制字符串inline string jtbg_dec2bin(long long n){ if (n == 0) return "0";
string result; bool neg = false;
if (n < 0) { neg = true; n = -n; }
while (n > 0) { result = char('0' + (n & 1)) + result; n >>= 1; }
if (neg) result = "-" + result; return result;}
// 二进制字符串转十进制inline long long jtbg_bin2dec(string s){ long long result = 0; bool neg = false;
if (s[0] == '-') { neg = true; s = s.substr(1); }
for (char c : s) { result <<= 1; if (c == '1') result |= 1; else if (c != '0') return 0; }
return neg ? -result : result;}
// 十进制转十六进制inline string jtbg_dec2hex(long long n){ if (n == 0) return "0";
string result; bool neg = false; const char hex_chars[] = "0123456789ABCDEF";
if (n < 0) { neg = true; n = -n; }
while (n > 0) { result = hex_chars[n & 0xF] + result; n >>= 4; }
if (neg) result = "-" + result; return result;}
// 十六进制转十进制inline long long jtbg_hex2dec(string s){ long long result = 0; bool neg = false;
if (s[0] == '-') { neg = true; s = s.substr(1); }
for (char c : s) { result <<= 4; if (c >= '0' && c <= '9')4 行未改动 result |= (c - 'a' + 10); else return 0; }
return neg ? -result : result;}
//===================================== 位运算扩展 =====================================104 行未改动全部展开#define JTBG_QUIK_ENDL '\n'#define jtdl JTBG_QUIK_ENDL#define syst system("cls")#define sys(x) system(x)#define noy_pause() system("pause > nul") #define noy_pause() system("pause > nul")#define pause() system("pause")#define to_int(x) atoi(x.c_str()) // 转换为int类型#define to_long(x) stol(x) // 转换为long类型#define to_double(x) stod(x) // 转换为double类型88 行未改动};#endif
#ifdef JTBG_LUHNstring prepluhn(const string& input) string prepluhn(const string& input){ string result; for(int i=0;i<int(input.size());i++) for(int i=0;i<int(input.size());i++) { char c=input[i]; if (isdigit(c)) if (isdigit(c)) { result+=c; } } return result;}
int toluhn(const string& num) int toluhn(const string& num){ string number=prepluhn(num); int sum = 0; bool doubleFlag = false; string reversed = number; reverse(reversed.begin(), reversed.end()); for(char c : reversed) for(char c : reversed) { if (!isdigit(c)) if (!isdigit(c)) { return -1; } int digit = c - '0'; if (doubleFlag) if (doubleFlag) { digit *= 2; if (digit > 9) if (digit > 9) { digit -= 9; } } sum += digit; doubleFlag = !doubleFlag; doubleFlag = !doubleFlag; } return (10 - (sum % 10)) % 10;}
bool visluhn(const string& fb) bool visluhn(const string& fb){ string fullNumber=prepluhn(fb); if (fullNumber.empty()) return false; string mainPart = fullNumber.substr(0, fullNumber.size() - 1);5 行未改动}#endif
#ifdef JTBG_WEBbool Iswebok() bool Iswebok(){ // INTERNET_CONNECTION_MODEM: 调制解调器 // INTERNET_CONNECTION_LAN: 局域网 // INTERNET_CONNECTION_WWAN: 移动网络(4G/5G) DWORD flags = 0; bool result = InternetGetConnectedState(&flags, 0); if (result) if (result) { if (flags & INTERNET_CONNECTION_LAN) return 1;//局域网 else if (flags & INTERNET_CONNECTION_MODEM) return 2;//调制解调器 else return 3;//其他 else return 3;//其他 } else return 0;}#endif293 行未改动全部展开 string cc_key_j= stdcc.ini_get_vol("key","cc_code"); string end_time_j= stdcc.ini_get_vol("cc","end_time"); string end_time_key_j= stdcc.ini_get_vol("key","end_time"); string ccluhn_j=stdcc.ini_get_vol("cc","luhn");
string key=stdcc.ini_get_vol("password","xor");
string per=xorpass(per_j,key); string per_key=xorpass(per_key_j,key); string cc=xorpass(cc_j,key); string cc_key=xorpass(cc_key_j,key); string end_time=xorpass(end_time_j,key); string end_time_key=xorpass(end_time_key_j,key); string ccluhn=xorpass(ccluhn_j,key);
if(MD5::hash(per)!=per_key) return CC_CHECK_BAD; else if(MD5::hash(cc)!=cc_key) return CC_CHECK_BAD; else if(MD5::hash(end_time)!=end_time_key) return CC_CHECK_BAD; if(int(end_time.size())==8)83 行未改动//GNUSenum class Gnuver{ V2, V3, V3, LGPL_V3, CHINESEGNU};string GetGnulicens(Gnuver version = Gnuver::V3){ switch (version) switch (version) { case Gnuver::CHINESEGNU: return R"(GNU通用公共许可协议第二版,1991年6月100 行未改动)";case Gnuver::V2:return R"(GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too.
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.
Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and modification follow.
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.
7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.
10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
one line to give the program's name and an idea of what it does.Copyright (C) yyyy name of author6 行未改动This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' to redistribute it under certain conditions; type `show c'for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyrightinterest in the program `Gnomovision'(which makes passes at compilers) written (which makes passes at compilers) writtenby James Hacker.
signature of Ty Coon, 1 April 1989Ty Coon, President of ViceThis General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License.
)";case Gnuver::V3:return R"(GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for software and other kinds of works.
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic2 行未改动 have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based on the Program.
To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work.
A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that2 行未改动 "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's4 行未改动 the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
The Corresponding Source for a work in source code form is that same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you2 行未改动 not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modifiedit, and giving a relevant date.
b) The work must carry prominent notices stating that it is7 行未改动additional terms, to the whole of the work, and all its parts,regardless of how they are packaged. This License gives nopermission to license the work in any other way, but it does notinvalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must displayAppropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
a) Convey the object code in, or embodied in, a physical product(including a physical distribution medium), accompanied by theCorresponding Source fixed on a durable physical mediumcustomarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product(including a physical distribution medium), accompanied by awritten offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product3 行未改动 medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of thewritten offer to provide the Corresponding Source. Thisalternative is allowed only occasionally and noncommercially, andonly if you received the object code with such an offer, in accord with subsection 6b.
d) Convey the object code by offering access from a designatedplace (gratis or for a charge), and offer equivalent access to theCorresponding Source in the same way through the same place at nofurther charge. You need not require recipients to copy the4 行未改动clear directions next to the object code saying where to find theCorresponding Source. Regardless of what server hosts theCorresponding Source, you remain obligated to ensure that it isavailable for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, providedyou inform other peers where the object code and CorrespondingSource of the work are being offered to the general public at nocharge under subsection 6d.13 行未改动 actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
"Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a2 行未改动 by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from theterms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or14 行未改动material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions;the above requirements apply either way.
10 行未改动 provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means,5 行未改动 actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered6 行未改动 conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at leastthe "copyright" line and a pointer to where the full notice is found.9 行未改动This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author> This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriateparts of the General Public License. Of course, your program's commandsmight be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General2 行未改动 )";case Gnuver::LGPL_V3:return R"(GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007
Copyright ? 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.
0. Additional Definitions. As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License.
“The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.
An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.
A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”.
The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.
The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:
a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, orb) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.3. Object Code Incorporating Material from Library Header Files.The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.b) Accompany the object code with a copy of the GNU GPL and this license document.4. Combined Works.You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:
a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.b) Accompany the Combined Work with a copy of the GNU GPL and this license document.c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following:0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.6. Revised Versions of the GNU Lesser General Public License.The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.29 行未改动if (a == b) return "0";
// 如果 a < b,交换并标记负号bool isNegative = false;if (!isGreaterOrEqual(a, b)) if (!isGreaterOrEqual(a, b)){swap(a, b);isNegative = true;}string result;int i = a.size() - 1, j = b.size() - 1;int borrow = 0;
while (i >= 0) while (i >= 0){int digitA = (a[i] - '0') - borrow;int digitB = (j >= 0) ? (b[j--] - '0') : 0;
if (digitA < digitB) if (digitA < digitB){digitA += 10;borrow = 1;} else }else{borrow = 0;}
17 行未改动return a >= b;}
// 移除前导零void removeLeadingZeros() void removeLeadingZeros(){size_t start = num.find_first_not_of('0');if (start == string::npos) if (start == string::npos){num = "0";sign = true; // 0的符号为正} }else{num = num.substr(start);}14 行未改动{sum += (a[i] - '0');i--;}if (j >= 0) if (j >= 0){sum += (b[j] - '0');j--;}80 行未改动Bigint() : num("0"), sign(true) {}
Bigint(string s){if (s.empty()) if (s.empty()){num = "0";sign = true;return;3 行未改动if (s[0] == '-'){sign = false;s = s.substr(1);} else }else{sign = true;}
5 行未改动return;}// 移除前导零size_t start = s.find_first_not_of('0');if (start == string::npos) if (start == string::npos){num = "0";sign = true; // 0总是正数} else }else{num = s.substr(start);// 如果数字是"0",确保符号为正if (num == "0") sign = true;15 行未改动string a = this->num;string b = other.num;bool aSign = this->sign;bool bSign = other.sign;if (aSign == bSign) if (aSign == bSign){string result = add(a, b);return Bigint(aSign ? result : "-" + result);}else else{if (aSign) // a正,b负 => a - |b|{string result = subtractNonNegative(a, b);if (result[0] == '-') if (result[0] == '-'){return Bigint("-" + result.substr(1));} else }else{return Bigint(result);}} }else // a负,b正 => b - |a|{string result = subtractNonNegative(b, a);if (result[0] == '-') if (result[0] == '-'){return Bigint("-" + result.substr(1));} else }else{return Bigint(result);}}18 行未改动
// 除法运算符Bigint operator/(const Bigint& other) const{if (other.num == "0") if (other.num == "0"){ throw runtime_error("Division by zero");}
7 行未改动
// 取模运算符Bigint operator%(const Bigint& other) const{ if (other.num == "0") if (other.num == "0") { throw runtime_error("Modulo by zero"); }
// 计算 a % b = a - (a / b) * b Bigint quotient = *this / other; Bigint product = quotient * other; Bigint remainder = *this - product;
return remainder;}Bigint& operator+=(const Bigint& other){19 行未改动{ *this = *this % other; return *this;}bool operator==(const Bigint& other) const bool operator==(const Bigint& other) const{ return (sign == other.sign) && (num == other.num);}bool operator!=(const Bigint& other) const bool operator!=(const Bigint& other) const{ return !(*this == other);}bool operator<(const Bigint& other) const bool operator<(const Bigint& other) const{ if (sign != other.sign) if (sign != other.sign) { return sign < other.sign; // 负数 < 正数 } if (sign) // 都是正数 { { if (num.length() != other.num.length()) return num.length() < other.num.length(); return num < other.num; } } else // 都是负数 { { if (num.length() != other.num.length()) return num.length() > other.num.length(); return num > other.num; }}bool operator>(const Bigint& other) const bool operator>(const Bigint& other) const{ return other < *this;}bool operator<=(const Bigint& other) const bool operator<=(const Bigint& other) const{ return !(*this > other);}bool operator>=(const Bigint& other) const bool operator>=(const Bigint& other) const{ return !(*this < other);}friend ostream& operator<<(ostream& os, const Bigint& bigint) friend ostream& operator<<(ostream& os, const Bigint& bigint){ if (!bigint.sign && bigint.num != "0") { os << '-';22 行未改动};#endif
#ifdef JTBG_KMPstruct kmp struct kmp{private: string pattern; vector<int> next;2 行未改动 int m = pattern.length(); next.resize(m, 0); next[0] = -1; int i = 0, j = -1; while (i < m - 1) while (i < m - 1) { if (j == -1 || pattern[i] == pattern[j]) if (j == -1 || pattern[i] == pattern[j]) { i++; j++; next[i] = j; } } else { j = next[j]; } } }
public: kmp(const string& pat) : pattern(pat) kmp(const string& pat) : pattern(pat) { buildNext(); }
// 搜索所有匹配位置 vector<int> search(const string& text) vector<int> search(const string& text) { vector<int> result; int n = text.length(); int m = pattern.length();
if (m == 0) return result;
int i = 0, j = 0; while (i < n) { if (j == -1 || text[i] == pattern[j]) if (j == -1 || text[i] == pattern[j]) { i++; j++; } else } else { j = next[j]; } if (j == m)
if (j == m) { result.push_back(i - j); j = next[j - 1]; // 继续搜索 i--; // 回退一步 } } return result; }
// 搜索第一个匹配位置,返回-1表示未找到 int findFirst(const string& text) int findFirst(const string& text) { int n = text.length(); int m = pattern.length();
if (m == 0) return 0;
int i = 0, j = 0; while (i < n && j < m) while (i < n && j < m) { if (j == -1 || text[i] == pattern[j]) if (j == -1 || text[i] == pattern[j]) { i++; j++; } else } else { j = next[j]; } }
return (j == m) ? (i - j) : -1; }
// 判断是否包含模式串 bool contains(const string& text) bool contains(const string& text) { return findFirst(text) != -1; }
// 获取next数组(用于调试) vector<int> getNext() const vector<int> getNext() const { return next; }
// 统计匹配次数 int count(const string& text) int count(const string& text) { return search(text).size(); }};5 行未改动 void pre(int argc,char** argv) { cout << "程序名: " << argv[0] << endl; cout << "参数数量: " << argc - 1 << endl; for (int i = 1; i < argc; i++)
for (int i = 1; i < argc; i++) { cout << "参数 " << i << ": " << argv[i] << endl; } }
vector<string> ToVector(int argc, char** argv) { vector<string> args; for (int i = 1; i < argc; i++) { args.push_back(string(argv[i])); } return args; } map<string, string> ToKeyValue(int argc, char** argv) map<string, string> ToKeyValue(int argc, char** argv) { map<string, string> params;
for (int i = 1; i < argc; i++) { string arg = argv[i];
// 检查是否是 --key=value 格式 if (arg.substr(0, 2) == "--") if (arg.substr(0, 2) == "--") { size_t pos = arg.find('='); if (pos != string::npos) if (pos != string::npos) { string key = arg.substr(2, pos - 2); string value = arg.substr(pos + 1); params[key] = value; } else } else { // 只有键没有值 params[arg.substr(2)] = "true"; } } // 检查是否是 -key value 格式 else if (arg.substr(0, 1) == "-") else if (arg.substr(0, 1) == "-") { string key = arg.substr(1); if (i + 1 < argc && argv[i + 1][0] != '-') if (i + 1 < argc && argv[i + 1][0] != '-') { params[key] = argv[i + 1]; i++; // 跳过下一个参数 } else } else { params[key] = "true"; } } }
return params; }};#endif84 行未改动 0, KEY_SET_VALUE, &hKey ); if (ret != ERROR_SUCCESS) if (ret != ERROR_SUCCESS) { return false; }
// 设置DWORD类型键值 ret = RegSetValueExW( hKey, valueName, 0, REG_DWORD, (const BYTE*)&value, sizeof(DWORD) ); if (ret != ERROR_SUCCESS) if (ret != ERROR_SUCCESS) { RegCloseKey(hKey); return false; }
RegCloseKey(hKey); // 关闭注册表句柄 return true;}bool SetShowFileExtensions(bool showExt=1)8 行未改动 0, // 保留参数 KEY_SET_VALUE, // 访问权限 &hKey // 输出打开的键句柄 ); if (ret != ERROR_SUCCESS) if (ret != ERROR_SUCCESS) { return false; } // 2. 设置键值:0表示显示,1表示隐藏5 行未改动 REG_DWORD, // 数据类型(32位整数) (const BYTE*)&value,// 数据缓冲区 sizeof(DWORD) // 数据长度 ); if (ret != ERROR_SUCCESS) if (ret != ERROR_SUCCESS) { RegCloseKey(hKey); // 关闭注册表句柄 return false; }3 行未改动 SHCNF_IDLIST, // 数据类型:ID列表(无具体数据时用此) nullptr, // 无具体数据 nullptr // 无具体数据 );
return true;}bool SetShowHiddenFiles(bool show) bool SetShowHiddenFiles(bool show){ const wchar_t* regPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"; DWORD value = show ? 1 : 2; // 注意:Hidden键的取值是1=显示,2=隐藏(特殊规则) if (!SetRegistryDwordValue(regPath, L"Hidden", value)) if (!SetRegistryDwordValue(regPath, L"Hidden", value)) { return false; } return true;}bool SetShowSystemFiles(bool show){ const wchar_t* regPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"; DWORD value = show ? 1 : 0; // 1=显示系统文件,0=隐藏 if (!SetRegistryDwordValue(regPath, L"ShowSuperHidden", value)) if (!SetRegistryDwordValue(regPath, L"ShowSuperHidden", value)) { return false; } return true;}bool SetHideEmptyDrives(bool hide) bool SetHideEmptyDrives(bool hide){ const wchar_t* regPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"; DWORD value = hide ? 1 : 0; // 1=隐藏无介质驱动器,0=显示 if (!SetRegistryDwordValue(regPath, L"HideDrivesWithNoMedia", value)) if (!SetRegistryDwordValue(regPath, L"HideDrivesWithNoMedia", value)) { return false; } return true;}bool ReadRegistryString(HKEY rootKey, const wchar_t* subKey, const wchar_t* valueName, wstring& outStr) bool ReadRegistryString(HKEY rootKey, const wchar_t* subKey, const wchar_t* valueName, wstring& outStr){ HKEY hKey = nullptr; LONG ret = RegOpenKeyExW(rootKey, subKey, 0, KEY_READ, &hKey); if (ret != ERROR_SUCCESS) if (ret != ERROR_SUCCESS) { return false; }
// 第一步:调用RegQueryValueExW获取字符串的长度(dataSize返回所需缓冲区大小) DWORD dataType = 0; DWORD dataSize = 0; ret = RegQueryValueExW(3 行未改动 &dataType, nullptr, // 缓冲区为null,仅获取长度 &dataSize ); if (ret != ERROR_SUCCESS && ret != ERROR_MORE_DATA) if (ret != ERROR_SUCCESS && ret != ERROR_MORE_DATA) { RegCloseKey(hKey); return false; }
// 第二步:分配缓冲区,读取字符串 bool success = false; if (dataType == REG_SZ || dataType == REG_EXPAND_SZ) if (dataType == REG_SZ || dataType == REG_EXPAND_SZ) { wchar_t* buffer = new wchar_t[dataSize / sizeof(wchar_t)]; // 按宽字符分配 ret = RegQueryValueExW( hKey,2 行未改动 &dataType, (LPBYTE)buffer, &dataSize ); if (ret == ERROR_SUCCESS) if (ret == ERROR_SUCCESS) { outStr = buffer; // 赋值到wstring success = true; } } delete[] buffer; // 释放缓冲区 } } RegCloseKey(hKey); return success;}bool ReadRegistryDword(HKEY rootKey, const wchar_t* subKey, const wchar_t* valueName, DWORD& outValue) bool ReadRegistryDword(HKEY rootKey, const wchar_t* subKey, const wchar_t* valueName, DWORD& outValue){ HKEY hKey = nullptr; LONG ret = RegOpenKeyExW( rootKey, subKey, 0, KEY_READ, &hKey ); if (ret != ERROR_SUCCESS) if (ret != ERROR_SUCCESS) { return false; }
// 2. 查询键值:先获取数据长度(此处DWORD固定为4字节,也可动态获取) DWORD dataType = 0; DWORD dataSize = sizeof(DWORD); ret = RegQueryValueExW(3 行未改动 &dataType, // 输出实际值类型 (LPBYTE)&outValue, // 存储读取的数据 &dataSize // 输入缓冲区大小,输出实际数据大小 );
// 3. 校验结果:类型匹配 + 操作成功 bool success = false; if (ret == ERROR_SUCCESS) if (ret == ERROR_SUCCESS) { if (dataType == REG_DWORD) if (dataType == REG_DWORD) { success = true; } } } RegCloseKey(hKey); return success;}47 行未改动#define RESUME 0#define SUSPEND 1
#ifndef NO_DEBUGPROSDWORD GetProcessIdByName(const char* processName) DWORD GetProcessIdByName(const char* processName){ DWORD processId = 0; HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnapshot != INVALID_HANDLE_VALUE)
if (hSnapshot != INVALID_HANDLE_VALUE) { PROCESSENTRY32 processEntry; processEntry.dwSize = sizeof(PROCESSENTRY32); if (Process32First(hSnapshot, &processEntry))
if (Process32First(hSnapshot, &processEntry)) { do do { if (strcmp(processEntry.szExeFile, processName) == 0) { processId = processEntry.th32ProcessID;6 行未改动 return processId;}
// 使用DebugActiveProcess挂起进程bool SuspendProcessByDebug(DWORD processId) bool SuspendProcessByDebug(DWORD processId){ if (DebugActiveProcess(processId)) { return true;3 行未改动
// 恢复被Debug挂起的进程bool ResumeProcessByDebug(DWORD processId){ if (DebugActiveProcessStop(processId)) if (DebugActiveProcessStop(processId)) { return true; } return false;10 行未改动#ifndef NO_NTPPORStypedef LONG (NTAPI *NtSuspendProcess)(IN HANDLE ProcessHandle);typedef LONG (NTAPI *NtResumeProcess)(IN HANDLE ProcessHandle);// 使用NtSuspendProcess挂起进程bool SuspendProcessByNt(DWORD processId) bool SuspendProcessByNt(DWORD processId){ HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId); if (hProcess == NULL) if (hProcess == NULL) { return false; }
// 获取NtSuspendProcess函数 HMODULE hNtDll = GetModuleHandle("ntdll.dll"); if (hNtDll == NULL) if (hNtDll == NULL) { CloseHandle(hProcess); return false; } NtSuspendProcess pNtSuspendProcess =
NtSuspendProcess pNtSuspendProcess = (NtSuspendProcess)GetProcAddress(hNtDll, "NtSuspendProcess"); if (pNtSuspendProcess != NULL)
if (pNtSuspendProcess != NULL) { LONG status = pNtSuspendProcess(hProcess); CloseHandle(hProcess); if (status == 0)
if (status == 0) { // STATUS_SUCCESS cout << "进程 " << processId << " 已被挂起 (Nt方法)" << endl; return true; } }
CloseHandle(hProcess); return false;}
// 恢复进程bool ResumeProcessByNt(DWORD processId){ HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId); if (hProcess == NULL) if (hProcess == NULL) { return false; }
HMODULE hNtDll = GetModuleHandle("ntdll.dll"); if (hNtDll == NULL) if (hNtDll == NULL) { CloseHandle(hProcess); return false; } NtResumeProcess pNtResumeProcess =
NtResumeProcess pNtResumeProcess = (NtResumeProcess)GetProcAddress(hNtDll, "NtResumeProcess"); if (pNtResumeProcess != NULL)
if (pNtResumeProcess != NULL) { LONG status = pNtResumeProcess(hProcess); CloseHandle(hProcess); if (status == 0)
if (status == 0) { cout << "进程 " << processId << " 已恢复 (Nt方法)" << endl; return true; } }
CloseHandle(hProcess); return false;}
8 行未改动#ifndef NO_TerminateProcessbool KillProcByTer(DWORD processId, UINT exitCode = 0){ HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, processId); if (hProcess == NULL) if (hProcess == NULL) { return false; } if (TerminateProcess(hProcess, exitCode))
if (TerminateProcess(hProcess, exitCode)) { CloseHandle(hProcess); return true; } else } else { CloseHandle(hProcess); return false; }}#endif
#ifndef NO_NTTERMINATEtypedef LONG (NTAPI *NtTerminateProcess)(HANDLE ProcessHandle, LONG ExitStatus);bool KillProcByNt(DWORD processId, LONG exitCode = 0) bool KillProcByNt(DWORD processId, LONG exitCode = 0){ HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, processId); if (hProcess == NULL) { return false; }
HMODULE hNtDll = GetModuleHandle("ntdll.dll"); if (hNtDll == NULL) { CloseHandle(hProcess); return false; } NtTerminateProcess pNtTerminateProcess =
NtTerminateProcess pNtTerminateProcess = (NtTerminateProcess)GetProcAddress(hNtDll, "NtTerminateProcess");
if (pNtTerminateProcess != NULL) { LONG status = pNtTerminateProcess(hProcess, exitCode); CloseHandle(hProcess);
if (status == 0) { // STATUS_SUCCESS return true; } }
CloseHandle(hProcess); return false;}#endifBOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam){ DWORD targetProcessId = (DWORD)lParam; DWORD windowProcessId;
GetWindowThreadProcessId(hwnd, &windowProcessId);
if (windowProcessId == targetProcessId) { // 发送关闭消息 PostMessage(hwnd, WM_CLOSE, 0, 0);5 行未改动 // 向进程的所有窗口发送关闭消息 EnumWindows(EnumWindowsProc, (LPARAM)processId); // 等待进程退出 HANDLE hProcess = OpenProcess(SYNCHRONIZE, FALSE, processId); if (hProcess == NULL) if (hProcess == NULL) { return KillProcByTer(processId); } DWORD waitResult = WaitForSingleObject(hProcess, waitTimeout); CloseHandle(hProcess); if (waitResult == WAIT_OBJECT_0) if (waitResult == WAIT_OBJECT_0) { return true; } } else { return KillProcByTer(processId); }}#endif
#ifdef JTBG_UDPclass UDPSocket class UDPSocket{public: // 手动实现 inet_pton (字符串转网络地址) static inet_pton(int af, const char* src, void* dst) static inet_pton(int af, const char* src, void* dst) { if (af != AF_INET) if (af != AF_INET) { return -1; // 只支持 IPv4 } uint32_t ip=0; int parts[4]; int count = sscanf(src, "%d.%d.%d.%d", &parts[0], &parts[1], &parts[2], &parts[3]); if (count != 4)
if (count != 4) { return 0; // 格式错误 } for (int i = 0; i < 4; i++)
for (int i = 0; i < 4; i++) { if (parts[i] < 0 || parts[i] > 255) { return 0; // 数值越界 } ip = (ip << 8) | (parts[i] & 0xFF); }
*((uint32_t*)dst) = htonl(ip); return 1; }
// 手动实现 inet_ntop (网络地址转字符串) static const char* inet_ntop(int af, const void* src, char* dst, socklen_t size) static const char* inet_ntop(int af, const void* src, char* dst, socklen_t size) { if (af != AF_INET || size < INET_ADDRSTRLEN) if (af != AF_INET || size < INET_ADDRSTRLEN) { return nullptr; }
uint32_t ip = ntohl(*((const uint32_t*)src)); snprintf(dst, size, "%d.%d.%d.%d", snprintf(dst, size, "%d.%d.%d.%d", (ip >> 24) & 0xFF, (ip >> 16) & 0xFF, (ip >> 16) & 0xFF, (ip >> 8) & 0xFF, ip & 0xFF);
return dst; } using ReceiveCallback = function<void(const vector<uint8_t>& data, const sockaddr_in& from, using ReceiveCallback = function<void(const vector<uint8_t>& data, const sockaddr_in& from, int dataSize)>; using ErrorCallback = function<void(const string& error)>;
// 构造函数和析构函数 UDPSocket(); ~UDPSocket();
// 禁止拷贝 UDPSocket(const UDPSocket&) = delete; UDPSocket& operator=(const UDPSocket&) = delete;
// 移动构造和赋值 UDPSocket(UDPSocket&& other) noexcept; UDPSocket& operator=(UDPSocket&& other) noexcept;
// 基本操作 bool create(); bool bind(uint16_t port, const string& address = "0.0.0.0"); bool close();
// 发送数据 int sendTo(const vector<uint8_t>& data, int sendTo(const vector<uint8_t>& data, const string& ip, uint16_t port); int sendTo(const uint8_t* data, size_t size, int sendTo(const uint8_t* data, size_t size, const string& ip, uint16_t port);
// 接收数据(阻塞模式) int receiveFrom(vector<uint8_t>& buffer, string& fromIP, uint16_t& fromPort, int receiveFrom(vector<uint8_t>& buffer, string& fromIP, uint16_t& fromPort, int timeoutMs = -1);
// 设置套接字选项 bool setBroadcast(bool enable); bool setReuseAddress(bool enable); bool setNonBlocking(bool enable); bool setReceiveBufferSize(int size); bool setSendBufferSize(int size); bool setTTL(int ttl);
// 异步操作 bool startAsyncReceive(const ReceiveCallback& receiveCallback, const ErrorCallback& errorCallback = nullptr); void stopAsyncReceive();
// 属性获取 bool isValid() const { return socket_ != INVALID_SOCKET; } uint16_t getLocalPort() const { return localPort_; } string getLocalAddress() const { return localAddress_; } bool isAsyncReceiving() const { return asyncReceiving_; }
private: SOCKET socket_; string localAddress_; uint16_t localPort_;
// 异步接收相关 atomic<bool> asyncReceiving_; thread receiveThread_; ReceiveCallback receiveCallback_; ErrorCallback errorCallback_;
// 初始化Winsock static bool initializeWinsock(); static void cleanupWinsock(); static atomic<int> winsockRefCount_;
// 线程函数 void asyncReceiveThread();
// 工具函数 static string ipToString(const sockaddr_in& addr); static uint16_t portFromSockaddr(const sockaddr_in& addr); static bool stringToSockaddr(const string& ip, uint16_t port, sockaddr_in& addr);};
// 实现部分inline UDPSocket::UDPSocket() inline UDPSocket::UDPSocket(): socket_(INVALID_SOCKET), localPort_(0), asyncReceiving_(false) , asyncReceiving_(false){ initializeWinsock();}
inline UDPSocket::~UDPSocket() inline UDPSocket::~UDPSocket(){ close(); stopAsyncReceive(); cleanupWinsock();2 行未改动inline UDPSocket::UDPSocket(UDPSocket&& other) noexcept: socket_(other.socket_), localAddress_(move(other.localAddress_)), localPort_(other.localPort_), asyncReceiving_(other.asyncReceiving_.load()) , asyncReceiving_(other.asyncReceiving_.load()){ other.socket_ = INVALID_SOCKET; other.asyncReceiving_ = false;}
inline UDPSocket& UDPSocket::operator=(UDPSocket&& other) noexcept inline UDPSocket& UDPSocket::operator=(UDPSocket&& other) noexcept{ if (this != &other) if (this != &other) { close(); stopAsyncReceive();
socket_ = other.socket_; localAddress_ = move(other.localAddress_); localPort_ = other.localPort_; asyncReceiving_ = other.asyncReceiving_.load();
other.socket_ = INVALID_SOCKET; other.asyncReceiving_ = false; } return *this;}
inline bool UDPSocket::initializeWinsock() inline bool UDPSocket::initializeWinsock(){ if (winsockRefCount_++ == 0) { WSADATA wsaData; WORD version = MAKEWORD(2, 2); if (WSAStartup(version, &wsaData) != 0) if (WSAStartup(version, &wsaData) != 0) { winsockRefCount_--; return false; } } return true;}
inline void UDPSocket::cleanupWinsock() inline void UDPSocket::cleanupWinsock(){ if (--winsockRefCount_ == 0) if (--winsockRefCount_ == 0) { WSACleanup(); }}
inline bool UDPSocket::create() inline bool UDPSocket::create(){ if (socket_ != INVALID_SOCKET) if (socket_ != INVALID_SOCKET) { return true; }
socket_ = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (socket_ == INVALID_SOCKET) if (socket_ == INVALID_SOCKET) { return false; }
return true;}
inline bool UDPSocket::bind(uint16_t port, const string& address){ if (!create()) if (!create()) { return false; }
sockaddr_in addr; if (!stringToSockaddr(address, port, addr)) { return false; }
if (::bind(socket_, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) == SOCKET_ERROR) { return false; }
// 获取绑定后的地址信息 sockaddr_in localAddr; int addrLen = sizeof(localAddr); if (getsockname(socket_, reinterpret_cast<sockaddr*>(&localAddr), &addrLen) == 0) if (getsockname(socket_, reinterpret_cast<sockaddr*>(&localAddr), &addrLen) == 0) { localAddress_ = ipToString(localAddr); localPort_ = portFromSockaddr(localAddr); }
return true;}
inline bool UDPSocket::close() inline bool UDPSocket::close(){ if (socket_ != INVALID_SOCKET) if (socket_ != INVALID_SOCKET) { ::closesocket(socket_); socket_ = INVALID_SOCKET; } return true;}
inline int UDPSocket::sendTo(const vector<uint8_t>& data, const string& ip, uint16_t port) inline int UDPSocket::sendTo(const vector<uint8_t>& data, const string& ip, uint16_t port){ return sendTo(data.data(), data.size(), ip, port);}
inline int UDPSocket::sendTo(const uint8_t* data, size_t size, inline int UDPSocket::sendTo(const uint8_t* data, size_t size, const string& ip, uint16_t port){ if (socket_ == INVALID_SOCKET || !data || size == 0) if (socket_ == INVALID_SOCKET || !data || size == 0) { return -1; }
sockaddr_in addr; if (!stringToSockaddr(ip, port, addr)) if (!stringToSockaddr(ip, port, addr)) { return -1; } int sent = ::sendto(socket_, reinterpret_cast<const char*>(data), static_cast<int>(size), 0, reinterpret_cast<sockaddr*>(&addr),
int sent = ::sendto(socket_, reinterpret_cast<const char*>(data), static_cast<int>(size), 0, reinterpret_cast<sockaddr*>(&addr), sizeof(addr));
if (sent == SOCKET_ERROR) { return -1; }
return sent;}
inline int UDPSocket::receiveFrom(vector<uint8_t>& buffer, string& fromIP, uint16_t& fromPort, inline int UDPSocket::receiveFrom(vector<uint8_t>& buffer, string& fromIP, uint16_t& fromPort, int timeoutMs) { if (socket_ == INVALID_SOCKET) { return -1; }
// 设置超时 if (timeoutMs >= 0) { fd_set readSet; FD_ZERO(&readSet); FD_SET(socket_, &readSet);
timeval timeout; timeout.tv_sec = timeoutMs / 1000; timeout.tv_usec = (timeoutMs % 1000) * 1000;
int result = select(0, &readSet, nullptr, nullptr, &timeout); if (result == 0) { return 0; // 超时 } } else if (result == SOCKET_ERROR) { return -1; } }
sockaddr_in fromAddr; int fromLen = sizeof(fromAddr); int received = ::recvfrom(socket_, reinterpret_cast<char*>(buffer.data()), static_cast<int>(buffer.size()), 0, reinterpret_cast<sockaddr*>(&fromAddr),
int received = ::recvfrom(socket_, reinterpret_cast<char*>(buffer.data()), static_cast<int>(buffer.size()), 0, reinterpret_cast<sockaddr*>(&fromAddr), &fromLen); if (received == SOCKET_ERROR)
if (received == SOCKET_ERROR) { return -1; }
fromIP = ipToString(fromAddr); fromPort = portFromSockaddr(fromAddr);
return received;}
inline bool UDPSocket::setBroadcast(bool enable){ if (socket_ == INVALID_SOCKET) return false;
BOOL broadcast = enable ? TRUE : FALSE; return setsockopt(socket_, SOL_SOCKET, SO_BROADCAST, return setsockopt(socket_, SOL_SOCKET, SO_BROADCAST, reinterpret_cast<char*>(&broadcast), sizeof(broadcast)) == 0;}
inline bool UDPSocket::setReuseAddress(bool enable){ if (socket_ == INVALID_SOCKET) return false;
BOOL reuse = enable ? TRUE : FALSE; return setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, return setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char*>(&reuse), sizeof(reuse)) == 0;}
inline bool UDPSocket::setNonBlocking(bool enable){ if (socket_ == INVALID_SOCKET) return false;
u_long mode = enable ? 1 : 0; return ioctlsocket(socket_, FIONBIO, &mode) == 0;}
inline bool UDPSocket::setReceiveBufferSize(int size) inline bool UDPSocket::setReceiveBufferSize(int size){ if (socket_ == INVALID_SOCKET) return false; return setsockopt(socket_, SOL_SOCKET, SO_RCVBUF,
return setsockopt(socket_, SOL_SOCKET, SO_RCVBUF, reinterpret_cast<char*>(&size), sizeof(size)) == 0;}
inline bool UDPSocket::setSendBufferSize(int size){ if (socket_ == INVALID_SOCKET) return false; return setsockopt(socket_, SOL_SOCKET, SO_SNDBUF,
return setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<char*>(&size), sizeof(size)) == 0;}
inline bool UDPSocket::setTTL(int ttl){ if (socket_ == INVALID_SOCKET) return false; return setsockopt(socket_, IPPROTO_IP, IP_TTL,
return setsockopt(socket_, IPPROTO_IP, IP_TTL, reinterpret_cast<char*>(&ttl), sizeof(ttl)) == 0;}
inline bool UDPSocket::startAsyncReceive(const ReceiveCallback& receiveCallback, const ErrorCallback& errorCallback) const ErrorCallback& errorCallback){ if (socket_ == INVALID_SOCKET || asyncReceiving_) { return false; }
receiveCallback_ = receiveCallback; errorCallback_ = errorCallback; asyncReceiving_ = true;
receiveThread_ = thread(&UDPSocket::asyncReceiveThread, this);
return true;}
inline void UDPSocket::stopAsyncReceive(){ if (asyncReceiving_) if (asyncReceiving_) { asyncReceiving_ = false; if (receiveThread_.joinable()) { receiveThread_.join(); } }}
inline void UDPSocket::asyncReceiveThread() inline void UDPSocket::asyncReceiveThread(){ vector<uint8_t> buffer(65507); // UDP最大数据包大小 while (asyncReceiving_)
while (asyncReceiving_) { string fromIP; uint16_t fromPort;
int received = receiveFrom(buffer, fromIP, fromPort, 100); // 100ms超时 if (received > 0 && receiveCallback_)
if (received > 0 && receiveCallback_) { sockaddr_in fromAddr; if (stringToSockaddr(fromIP, fromPort, fromAddr)) if (stringToSockaddr(fromIP, fromPort, fromAddr)) { vector<uint8_t> data(buffer.begin(), buffer.begin() + received); receiveCallback_(data, fromAddr, received); } } else if (received == SOCKET_ERROR && errorCallback_) } else if (received == SOCKET_ERROR && errorCallback_) { errorCallback_("接收数据出错"); } }19 行未改动{ memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(port);
if (ip.empty() || ip == "0.0.0.0") { addr.sin_addr.s_addr = INADDR_ANY; } else if (ip == "255.255.255.255") } else if (ip == "255.255.255.255") { addr.sin_addr.s_addr = INADDR_BROADCAST; } else } else { if (inet_pton(AF_INET, ip.c_str(), &addr.sin_addr) != 1) if (inet_pton(AF_INET, ip.c_str(), &addr.sin_addr) != 1) { return false; } }
return true;}
#endif6 行未改动#define PROGRESS_STYLE_DEFAULT "|"#define PROGRESS_STYLE_BLOCK "="#define PROGRESS_STYLE_DASH "-"
class BarDrawer class BarDrawer{ // 修正类名与使用处一致private: int total; // 总进度值 int current; // 当前进度值 int barLength; // 进度条长度 string style; // 进度条样式 bool showPercent; // 是否显示百分比 bool showTime; // 是否显示时间 chrono::steady_clock::time_point startTime; // 开始时间
public: // 构造函数(修正:使用正确的构造函数语法) BarDrawer(int totalSteps, int length = 50, BarDrawer(int totalSteps, int length = 50, string barStyle = PROGRESS_STYLE_DEFAULT, bool percent = true, bool time = true) : total(totalSteps), current(0), barLength(length), style(barStyle), showPercent(percent), showTime(time) bool percent = true, bool time = true) : total(totalSteps), current(0), barLength(length), style(barStyle), showPercent(percent), showTime(time) { startTime = chrono::steady_clock::now(); }
// 无参构造函数(解决实例化时的参数匹配问题) BarDrawer() : total(100), current(0), barLength(50), style(PROGRESS_STYLE_DEFAULT), showPercent(true), showTime(true) BarDrawer() : total(100), current(0), barLength(50), style(PROGRESS_STYLE_DEFAULT), showPercent(true), showTime(true) { startTime = chrono::steady_clock::now(); }
// 更新进度 void update(int steps = 1) void update(int steps = 1) { current = min(current + steps, total); draw(); }
// 直接设置进度 void setProgress(int value) void setProgress(int value) { current = max(0, min(value, total)); draw(); }
// 完成进度 void finish() void finish() { current = total; draw(); cout << endl; }
// 绘制进度条(修正:添加返回值或改为void) void draw() void draw() { double progress = static_cast<double>(current) / total; int filledLength = static_cast<int>(progress * barLength);
// 计算已用时间 auto now = chrono::steady_clock::now(); auto elapsed = chrono::duration_cast<chrono::seconds>( now - startTime).count();
// 绘制进度条(结合JTBG_COL模块的颜色功能) scg(LIGHT_GREEN, BLACK); // 设置绿色文本 cout << "\r["; for (int i = 0; i < barLength; ++i) for (int i = 0; i < barLength; ++i) { if (i < filledLength) cout << style; else cout << " "; } cout << "] ";
// 显示百分比 if (showPercent) if (showPercent) { scg(LIGHT_CYAN, BLACK); // 百分比用青色 cout << fixed << setprecision(1) cout << fixed << setprecision(1) << progress * 100 << "% "; }
// 显示进度数值 scg(WHITE, BLACK); // 数值用白色 cout << current << "/" << total;
// 显示时间 if(showTime) if(showTime) { scg(YELLOW, BLACK); cout << " (" << elapsed << "s)"; }
scg(WHITE, BLACK); // 恢复默认颜色 cout.flush(); }};12 行未改动{private: string num; bool negative;
// 移除前导零 void removeLeadingZeros() void removeLeadingZeros() { size_t pos = num.find_first_not_of('0'); if (pos == string::npos) if (pos == string::npos) { num = "0"; negative = false; } else } else { num = num.substr(pos); } if (num == "0") negative = false; }
// 比较绝对值大小 int compareAbsolute(const SimpleBigInt& other) const { if (num.length() != other.num.length()) if (num.length() != other.num.length()) { return num.length() > other.num.length() ? 1 : -1; } return num.compare(other.num); }
public: // 构造函数 SimpleBigInt() : num("0"), negative(false) {} SimpleBigInt(long long n) SimpleBigInt(long long n) { if (n < 0) { negative = true; n = -n; } else } else { negative = false; } num = to_string(n); } SimpleBigInt(const string& s) SimpleBigInt(const string& s) { if (s.empty()) if (s.empty()) { num = "0"; negative = false; } } else { if (s[0] == '-') if (s[0] == '-') { negative = true; num = s.substr(1); } else } else { negative = false; num = s; } } removeLeadingZeros(); }
// 转换为字符串 string toString() const string toString() const { return (negative ? "-" : "") + num; }
// 获取数字字符串(无符号) string getNum() const { return num; }
// 获取符号 bool isNegative() const { return negative;
}
// 比较运算符 bool operator==(const SimpleBigInt& other) const { return negative == other.negative && num == other.num; }
bool operator!=(const SimpleBigInt& other) const { return !(*this == other); }
bool operator<(const SimpleBigInt& other) const { if (negative != other.negative) {4 行未改动 return compareAbsolute(other) > 0; } return compareAbsolute(other) < 0; }
bool operator<=(const SimpleBigInt& other) const { return *this < other || *this == other; }
bool operator>(const SimpleBigInt& other) const { return !(*this <= other);
} bool operator>=(const SimpleBigInt& other) const
bool operator>=(const SimpleBigInt& other) const { return !(*this < other); }
// 加法 SimpleBigInt operator+(const SimpleBigInt& other) const { if (negative != other.negative) { // 符号不同,转换为减法 if (negative) if (negative) { SimpleBigInt temp = *this; temp.negative = false; return other - temp; } else } else { SimpleBigInt temp = other; temp.negative = false; return *this - temp; } }
// 符号相同,直接相加 string result; int carry = 0; int i = num.length() - 1; int j = other.num.length() - 1;
while (i >= 0 || j >= 0 || carry > 0) { int digit1 = i >= 0 ? num[i] - '0' : 0; int digit2 = j >= 0 ? other.num[j] - '0' : 0; int sum = digit1 + digit2 + carry;
result.push_back((sum % 10) + '0'); carry = sum / 10;
i--; j--; }
reverse(result.begin(), result.end()); SimpleBigInt res(result); res.negative = negative; return res; }
// 减法 SimpleBigInt operator-(const SimpleBigInt& other) const { if (negative != other.negative) if (negative != other.negative) { // 符号不同,转换为加法 SimpleBigInt temp = other; temp.negative = !other.negative; return *this + temp; }
// 符号相同,比较大小 bool resultNegative = false; string a = num; string b = other.num; if (negative)
if (negative) { // 都是负数:(-a) - (-b) = b - a swap(a, b); resultNegative = (compareAbsolute(other) > 0); } } else { // 都是正数:a - b if (*this < other) if (*this < other) { swap(a, b); resultNegative = true; } }
// 执行减法 string result; int borrow = 0; int i = a.length() - 1; int j = b.length() - 1;
while (i >= 0) { int digit1 = a[i] - '0' - borrow; int digit2 = j >= 0 ? b[j] - '0' : 0; if (digit1 < digit2)
if (digit1 < digit2) { digit1 += 10; borrow = 1; } } else { borrow = 0; }
result.push_back((digit1 - digit2) + '0');
i--; j--; }
// 移除结果中的前导零 while (result.length() > 1 && result.back() == '0') while (result.length() > 1 && result.back() == '0') { result.pop_back(); }
reverse(result.begin(), result.end()); SimpleBigInt res(result); res.negative = resultNegative; return res; }
// 乘法 SimpleBigInt operator*(const SimpleBigInt& other) const { if (num == "0" || other.num == "0") if (num == "0" || other.num == "0") { return SimpleBigInt("0"); }
int len1 = num.length(); int len2 = other.num.length(); vector<int> result(len1 + len2, 0);
// 从低位到高位相乘 for (int i = len1 - 1; i >= 0; i--) { for (int j = len2 - 1; j >= 0; j--) for (int j = len2 - 1; j >= 0; j--) { int mul = (num[i] - '0') * (other.num[j] - '0'); int sum = mul + result[i + j + 1];
result[i + j + 1] = sum % 10; result[i + j] += sum / 10; } }
// 转换为字符串 string strResult; for (int digit : result) { if (!(strResult.empty() && digit == 0)) if (!(strResult.empty() && digit == 0)) { strResult.push_back(digit + '0'); } }
if (strResult.empty()) strResult = "0";
SimpleBigInt res(strResult); res.negative = (negative != other.negative); return res; }
// 除法(返回商和余数) pair<SimpleBigInt, SimpleBigInt> divide(const SimpleBigInt& divisor) const { if (divisor == SimpleBigInt("0")) { throw runtime_error("Division by zero"); }
SimpleBigInt dividend = *this; dividend.negative = false; SimpleBigInt div = divisor; div.negative = false;
if (dividend < div) { return {SimpleBigInt("0"), *this}; }
string quotient; string current;
for (char digit : dividend.num) { current.push_back(digit); SimpleBigInt cur(current);
int count = 0; while (cur >= div) while (cur >= div) { cur = cur - div; count++; }
quotient.push_back(count + '0'); current = cur.num;
if (current == "0") { current.clear(); } }
// 移除商的前导零 size_t pos = quotient.find_first_not_of('0'); if (pos == string::npos) if (pos == string::npos) { quotient = "0"; } else { quotient = quotient.substr(pos); }
SimpleBigInt q(quotient); SimpleBigInt r(current.empty() ? "0" : current);
q.negative = (negative != divisor.negative); r.negative = negative; // 余数符号与被除数相同
return {q, r}; }
// 除法运算符(返回商) SimpleBigInt operator/(const SimpleBigInt& other) const { return divide(other).first; }
// 取模运算符 SimpleBigInt operator%(const SimpleBigInt& other) const { return divide(other).second; }
// 快速幂取模(核心算法) static SimpleBigInt modPow(SimpleBigInt base, SimpleBigInt exponent, SimpleBigInt modulus) static SimpleBigInt modPow(SimpleBigInt base, SimpleBigInt exponent, SimpleBigInt modulus) { if (modulus == SimpleBigInt("1")) return SimpleBigInt("0"); if (exponent == SimpleBigInt("0")) return SimpleBigInt("1");
SimpleBigInt result("1"); base = base % modulus;
// 将指数转换为二进制字符串 string binary; SimpleBigInt exp = exponent; while (exp > SimpleBigInt("0"))
while (exp > SimpleBigInt("0")) { // 检查最低位 pair<SimpleBigInt, SimpleBigInt> divResult = exp.divide(SimpleBigInt("2")); if (divResult.second == SimpleBigInt("1")) { binary = "1" + binary; } } else { binary = "0" + binary; } exp = divResult.first; // exp = exp / 2 }
// 快速幂算法 for (char bit : binary) for (char bit : binary) { result = (result * result) % modulus; if (bit == '1') if (bit == '1') { result = (result * base) % modulus; } }
return result; } static pair<SimpleBigInt, SimpleBigInt> extendedGcd(SimpleBigInt a, SimpleBigInt b) { if (b == SimpleBigInt("0")) { return {SimpleBigInt("1"), SimpleBigInt("0")}; }
pair<SimpleBigInt, SimpleBigInt> temp = extendedGcd(b, a % b); SimpleBigInt x1 = temp.first; SimpleBigInt y1 = temp.second; SimpleBigInt x = y1; SimpleBigInt y = x1 - (a / b) * y1;
return {x, y}; }
// 模逆元 static SimpleBigInt modInverse(SimpleBigInt a, SimpleBigInt m) { pair<SimpleBigInt, SimpleBigInt> gcdResult = extendedGcd(a, m); SimpleBigInt x = gcdResult.first; SimpleBigInt y = gcdResult.second;
// 检查是否有逆元 (gcd(a, m) 必须为1) SimpleBigInt gcd = a * x + m * y; if (gcd != SimpleBigInt("1")) if (gcd != SimpleBigInt("1")) { return SimpleBigInt("-1"); // 无逆元 }
// 确保结果为正 SimpleBigInt result = x % m; if (result.isNegative()) { result = result + m; }
return result; }};
// ============ RSA 实现 ============namespace RSA namespace RSA{ using BigInt = SimpleBigInt; struct RSAKey
struct RSAKey { BigInt n; // 模数 BigInt e; // 公钥指数 BigInt d; // 私钥指数 };
// Miller-Rabin 素性测试(简化版) bool isPrimeSimple(const BigInt& n, int k = 5) bool isPrimeSimple(const BigInt& n, int k = 5) { if (n == BigInt("2") || n == BigInt("3")) return true; if (n < BigInt("2") || n % BigInt("2") == BigInt("0")) return false;
// 将 n-1 分解为 d * 2^s BigInt d = n - BigInt("1"); int s = 0; while (d % BigInt("2") == BigInt("0")) while (d % BigInt("2") == BigInt("0")) { d = d / BigInt("2"); s++; }
srand(time(nullptr));
for (int i = 0; i < k; i++) { // 随机选择基数 a BigInt a(to_string(2 + rand() % 100)); // 简化:使用小随机数
if (a >= n - BigInt("1")) { a = BigInt("2"); }
BigInt x = BigInt::modPow(a, d, n);
if (x == BigInt("1") || x == n - BigInt("1")) { continue; }
bool composite = true; for (int j = 0; j < s - 1; j++) for (int j = 0; j < s - 1; j++) { x = (x * x) % n; if (x == n - BigInt("1")) { composite = false; break; } }
if (composite) { return false; } }
return true; }
// 生成素数(简化版) BigInt generatePrimeSimple(int bits = 16) { if (bits < 8) bits = 8;
srand(time(nullptr)); int maxAttempts = 1000;
for (int attempt = 0; attempt < maxAttempts; attempt++) { // 生成随机数 string numStr = "1"; // 确保最高位是1 for (int i = 1; i < bits - 1; i++)
for (int i = 1; i < bits - 1; i++) { numStr += (rand() % 2) ? '1' : '0'; } numStr += '1'; // 确保是奇数
BigInt candidate(numStr);
// 快速检查小素数 vector<int> smallPrimes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29}; bool divisible = false; for (int prime : smallPrimes)
for (int prime : smallPrimes) { if (candidate % BigInt(to_string(prime)) == BigInt("0")) if (candidate % BigInt(to_string(prime)) == BigInt("0")) { divisible = true; break; } }
if (divisible) continue;
// 简化素性测试 if (isPrimeSimple(candidate)) if (isPrimeSimple(candidate)) { return candidate; } }
// 如果没找到,返回一个已知的素数 return BigInt("101"); }
// 生成RSA密钥对 // 生成RSA密钥对(修复版) RSAKey generateKeyPair(int keySize = 64) RSAKey generateKeyPair(int keySize = 64) { RSAKey key;
// 生成两个不同的素数 BigInt p = generatePrimeSimple(keySize / 2); BigInt q = generatePrimeSimple(keySize / 2);
while (q == p) { q = generatePrimeSimple(keySize / 2); }
// 计算 n = p * q key.n = p * q;
// 计算 φ(n) = (p-1)*(q-1) BigInt phi = (p - BigInt("1")) * (q - BigInt("1"));
// 选择公钥指数 e(常用值) vector<int> eCandidates = {3, 5, 17, 257, 65537}; bool found = false;
for (int eVal : eCandidates) { key.e = BigInt(to_string(eVal));
// 修复:不使用结构化绑定 pair<SimpleBigInt, SimpleBigInt> gcdResult = BigInt::extendedGcd(key.e, phi); SimpleBigInt gcd = gcdResult.first * key.e + gcdResult.second * phi;
if (gcd == BigInt("1")) { found = true; break; } }
if (!found) { // 尝试较小的奇数 for (int eVal = 3; eVal < 100; eVal += 2) for (int eVal = 3; eVal < 100; eVal += 2) { key.e = BigInt(to_string(eVal));
// 修复:不使用结构化绑定 pair<SimpleBigInt, SimpleBigInt> gcdResult = BigInt::extendedGcd(key.e, phi); SimpleBigInt gcd = gcdResult.first * key.e + gcdResult.second * phi;
if (gcd == BigInt("1")) { found = true; break; } } }
if (!found) { // 使用默认值 key.e = BigInt("65537"); }
// 计算私钥指数 d = e^(-1) mod φ(n) key.d = BigInt::modInverse(key.e, phi);
return key; }
// 字符串编码为数字 BigInt stringToNumber(const string& str) BigInt stringToNumber(const string& str) { string encoded; for (char c : str) for (char c : str) { int ascii = static_cast<int>(c); stringstream ss; ss << setw(3) << setfill('0') << ascii; encoded += ss.str(); } return BigInt(encoded); }
// 数字解码为字符串 string numberToString(const BigInt& num) { string numStr = num.getNum(); string decoded;
// 补全到3的倍数 while (numStr.length() % 3 != 0) { numStr = "0" + numStr; }
for (size_t i = 0; i < numStr.length(); i += 3) { string triplet = numStr.substr(i, 3); int ascii = stoi(triplet); if (ascii >= 32 && ascii <= 126) if (ascii >= 32 && ascii <= 126) { // 可打印字符 decoded += static_cast<char>(ascii); } }
return decoded; }
// RSA加密 BigInt rsaEncrypt(const BigInt& message, const BigInt& e, const BigInt& n) { return BigInt::modPow(message, e, n); }
// RSA解密 BigInt rsaDecrypt(const BigInt& ciphertext, const BigInt& d, const BigInt& n) BigInt rsaDecrypt(const BigInt& ciphertext, const BigInt& d, const BigInt& n) { return BigInt::modPow(ciphertext, d, n); }
// 字符串加密 string encryptString(const string& plaintext, const BigInt& e, const BigInt& n) { BigInt encoded = stringToNumber(plaintext); BigInt encrypted = rsaEncrypt(encoded, e, n); return encrypted.toString(); }
// 字符串解密 string decryptString(const string& ciphertext, const BigInt& d, const BigInt& n) { BigInt cipherNum(ciphertext); BigInt decrypted = rsaDecrypt(cipherNum, d, n); return numberToString(decrypted); }
// 演示函数 void demo() { cout << "\n=== 简单RSA演示 ===" << endl; cout << "注意:这是一个独立实现,不依赖外部库" << endl;
// 生成密钥对 cout << "\n1. 生成RSA密钥对..." << endl; RSAKey key = generateKeyPair(32);
cout << "公钥 (n, e):" << endl; cout << " n = " << key.n.toString() << endl; cout << " e = " << key.e.toString() << endl;
cout << "\n私钥 (n, d):" << endl; cout << " n = " << key.n.toString() << endl; cout << " d = " << key.d.toString() << endl;
// 测试消息 string testMessage = "HELLO"; cout << "\n2. 测试加密/解密" << endl; cout << "原始消息: \"" << testMessage << "\"" << endl;
// 加密 string encrypted = encryptString(testMessage, key.e, key.n); cout << "加密后: " << encrypted << endl;
// 解密 string decrypted = decryptString(encrypted, key.d, key.n); cout << "解密后: \"" << decrypted << "\"" << endl;
if (testMessage == decrypted) { cout << "\n? RSA加解密成功!" << endl; } else else { cout << "\n? RSA加解密失败!" << endl; }
// 额外测试:验证数学运算 cout << "\n3. 验证数学运算" << endl; cout << "测试: 5^3 mod 13" << endl; BigInt testResult = BigInt::modPow(BigInt("5"), BigInt("3"), BigInt("13"));729 行未改动全部展开