2015-06-23 77 views
1

我必須在swift中使用大量數字(以實現RSA算法),所以我正在尋找與Java的BigInteger類相當的功能。在另一個主題中,我發現了這一個:https://github.com/kirsteins/BigInteger 所以我試圖將這個添加到我的項目中,遵循以下步驟: - 我下載並添加BigInteger.xcodeproj到我的項目 在「Build Phases」中: - Add 「BigInteger的」在「目標相關」 - 「從‘BigInteger的’IN‘的BigInteger’項目的目標BigInteger.framework」到「鏈接二進制與圖書館」添加 - 添加「BigInteger.framework」到「複製文件」Swift:添加BigInteger框架

當我構建項目時,它「構建失敗」,但我不明白爲什麼有問題。我發現YouTube上的一個視頻https://www.youtube.com/watch?v=NBmfGdbOrMs描述的步驟,我完全按照這些步驟,但問題仍然在這裏...

你有同樣的問題嗎?你找到解決方案嗎?

回答

0

我寫了一個大整數和大的雙快速實現,這不需要任何額外的庫。只需將其複製到您的項目中。它支持大多數常用數學運算符(如加法,減法,乘法,取冪,模數和除法)的整數(BInt)和分數(BDouble)。一些優化的數學函數,如階乘或gcd也被實現。

下面是一些代碼示例:

// Create a new number: 
let num = BInt(232) 
print(num) // prints "232" 

// You can also use Strings to create a number: 
let veryBig = BInt("-827846184963421874362418746238453267452971345218746328715380000000000") 

// Every standard math operator works well, even with normal Integers 
// Visit the github page for more informations 
let v0 = (BInt(5) + BInt(4)) - BInt(3) 
let v1 = veryBig * 1000 
let v2 = vergBig^num 
let v3 = (veryBig^50000)/(BInt(2)^900) + 1 
let v4 = gcd(abs(veryBig), num) 

// BDouble is very similar, you can find a detailed description on Github 
let fraction = BDouble("27", over: "31") 
print(fraction) // prints "27/31" 

您可以自由使用它沒有給我的信用,如果你想請貢獻。

您可以在這裏找到它:https://github.com/mkrd/Swift-Big-Integer