From 70a7537584889cf612ddea83eb65fd42818f6e5e Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Fri, 7 Oct 2016 22:06:29 +0200 Subject: Make code work on Linux and older compilers --- Makefile | 8 ++++++-- bigint.cpp | 2 +- bigint.h | 8 ++++---- main.cpp | 3 ++- rng.cpp | 6 ++++++ 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 14220de..5778290 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,14 @@ CXX = g++ -CXXFLAGS = -Wall -Wextra -std=c++11 -fwrapv +CXXFLAGS = -Wall -Wextra -std=c++0x -fwrapv +LDFLAGS = ifneq ($(DEBUG),) CXXFLAGS += -g else CXXFLAGS += -O2 endif +ifeq ($(shell uname),Linux) + LDFLAGS += -lbsd +endif BIN = main .PHONY: all clean remake @@ -18,7 +22,7 @@ remake: clean all $(BIN): $(patsubst %.cpp,%.o,$(wildcard *.cpp)) - $(CXX) -o $@ $^ + $(CXX) -o $@ $^ $(LDFLAGS) %.o: %.cpp $(wildcard *.h) $(CXX) $(CXXFLAGS) -c -o $@ $< diff --git a/bigint.cpp b/bigint.cpp index 1f71cf9..98846e0 100644 --- a/bigint.cpp +++ b/bigint.cpp @@ -617,7 +617,7 @@ std::ostream& operator<<(std::ostream &os,Bigint b){ return os; #else if(b==0)return os<<'0'; - Bigint div(1000000000000000000LL); + Bigint div((int64_t)1000000000000000000LL); vector outbuf; while(b!=0){ pair dm=b.divmod(div); diff --git a/bigint.h b/bigint.h index 24f0945..bd15fd9 100644 --- a/bigint.h +++ b/bigint.h @@ -8,10 +8,10 @@ class Bigint{ public: - using digit_t=uint32_t; - using sdigit_t=int32_t; - using longdigit_t=uint64_t; - using slongdigit_t=int64_t; + typedef uint32_t digit_t; + typedef int32_t sdigit_t; + typedef uint64_t longdigit_t; + typedef int64_t slongdigit_t; static const int digit_bits=8*sizeof(digit_t); private: diff --git a/main.cpp b/main.cpp index 2cd31ec..0481f6c 100644 --- a/main.cpp +++ b/main.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -133,7 +134,7 @@ void testisqrt(int argc,char **argv){ void performrsa(){ RSA::PrivateKey privkey; Bigint p(1000000007),q(3000000019U); - privkey.pub.mod=3000000040000000133LL; + privkey.pub.mod=(int64_t)3000000040000000133LL; privkey.pub.exp=65537; { Bigint x; diff --git a/rng.cpp b/rng.cpp index aba1c02..a6c61f5 100644 --- a/rng.cpp +++ b/rng.cpp @@ -4,6 +4,12 @@ #include #include "rng.h" +#ifdef __APPLE__ +#include +#else +#include +#endif + using namespace std; -- cgit v1.2.3-70-g09d2